Bubble Sorting
C Program For Bubble Sorting Source Code: #include<stdio.h> #include<conio.h> #include<stdio.h> #include<conio.h> void main() { int a[50],n,i,j,t; i=0; j=0; clrscr(); printf("enter the number of elements in the array:"); scanf("%d",&n); printf("the elements are:"); for(i=0;i<n;i++) scanf("%d",&a[i]); printf("\nthe array is:"); for(i=0;i<n;i++) printf("%d\t",a[i]); for(i=0;i<n-1;i++) { for(j=0;j<n-i-1;j++) { if(a[j]>a[j+1]) { t=a[j]; a[j]=a[j+1]; a[j+1]=t; } } } printf("\nthe number of passes is %d",i); printf("\nthe sorted arrray is:"); for(i=0;i<n;i++) { printf("%d\t",a[i]); } getch(); } output: enter the number of elements in the array:5 the elements are:5 15 25 12 20 the array is: 5 15 25 12 20 the number of passes is 4 the sorted arrray is: 5 12 15 20 25
Tags:
Sorting
0 comments