forked from jrabhishek/dsa_assignment1
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path4.c
More file actions
43 lines (37 loc) · 669 Bytes
/
Copy path4.c
File metadata and controls
43 lines (37 loc) · 669 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include<stdlib.h>
#include<stdio.h>
int main()
{
int n,*array,i,j;
printf("enter no of elements\n");
scanf("%d",&n);
array = (int*)malloc(n * sizeof(int));
if (array == NULL)
{
return 0;
}
printf("enter elements in array\n");
for( i = 0; i < n; ++i)
{
scanf("%d",array+i);
}
for (i = 0; i < n-1; ++i)
{
for ( j = i+1; j < n; ++j)
{
if (array[i]>array[j])
{
//swap
array[i] += array[j];
array[j] = array[i] - array[j];
array[i] = array[i] - array[j];
}
}
}
printf("==============================================================\n");
for( i = 0; i < n; ++i)
{
printf("%d\n",array[i] );
}
free(array);
}