-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBubble_Sort.c
More file actions
34 lines (34 loc) · 749 Bytes
/
Bubble_Sort.c
File metadata and controls
34 lines (34 loc) · 749 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
#include<stdio.h>
int main()
{
int A[100],i,j,n,temp,flag;
printf("Enter the number of elements : ");
scanf("%d",&n);
printf("Enter the %d elements separated by space : ",n);
for(i=0;i<n;i++)
scanf("%d",&A[i]);
printf("Your unsorted elements are : ");
for(i=0;i<n;i++)
printf("%d ",A[i]);
printf("\n");
for(i=0;i<n-1;i++)
{
flag=0;
for(j=0;j<n-1-i;j++)
{
if(A[j]>A[j+1])
{
temp=A[j];
A[j]=A[j+1];
A[j+1]=temp;
flag=1;
}
}
if(flag==0)
break;
}
printf("The sorted elements are : ");
for(i=0;i<n;i++)
printf("%d ",A[i]);
printf("\n");
}