-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubble.c
More file actions
38 lines (33 loc) · 900 Bytes
/
Copy pathbubble.c
File metadata and controls
38 lines (33 loc) · 900 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
/*-------------------------------------------------------------------------------------------------------------------------------
Bubble.c
Program to sort n numbers in ascending order using bubble sort.
DIVYA RAJ K
25-09-2018
---------------------------------------------------------------------------------------------------------------------------------*/
#include<stdio.h>
#include<math.h>
main()
{
int X[30],N,i,j,Temp;
system("clear");
printf("Program to sort n numbers in ascending order using bubble sort\n\n");
printf("Enter the number of elements: ");
scanf("%d",&N);
printf("Enter %d numbers:\n",N);
for(i=1;i<=N;i++){
scanf("%d",&X[i]);
}
for(i=1;i<=(N-1);i++){
for(j=1;j<=(N-i);j++){
if(X[j]>X[j+1]){
Temp=X[j];
X[j]=X[j+1];
X[j+1]=Temp;
}
}
}
printf("\nThe entered numbers after sorting are:\n");
for(i=1;i<=N;i++){
printf("%d\t",X[i]);
}
}