Skip to content

Commit c661f05

Browse files
Create BubbleSort.c
1 parent 8b3bcb3 commit c661f05

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

BubbleSort.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include<stdio.h>
2+
void main()
3+
{
4+
int i,j,no,c,temp;
5+
printf(" Enter The Size of 1D Array\n");
6+
scanf(" %d", &no);
7+
int arr[no];
8+
printf(" Enter The Elements into the Array: \n");
9+
for(i=0;i<no;i++)
10+
scanf("%d",&arr[i]);
11+
printf("\n\n The Given Array Is:\n \n");
12+
for(i=0;i<no;i++)
13+
printf("%d ",arr[i]);
14+
/*BUBBLE SORT*/
15+
printf("\n\n The Sorted Array Is: \n\n");
16+
for(j=0;j<no;j++)
17+
{
18+
for(i=(no-1);i>c;i--)
19+
{
20+
if(arr[i]<arr[i-1])
21+
{
22+
temp=arr[i-1];
23+
arr[i-1]=arr[i];
24+
arr[i]=temp;
25+
}
26+
else
27+
continue;
28+
}
29+
++c;
30+
}
31+
for(i=0;i<no;i++)
32+
printf("%d ", arr[i]);
33+
printf("\n");
34+
}
35+

0 commit comments

Comments
 (0)