Saved Bookmarks
| 1. |
Write an algorithm to sort an arrays of integers using bubble sort technique. |
|
Answer» A C algorithm to sort an array using bubble sort technique void main() { int a[20],i,j,n,c,flag; printf("how many numbers u want to enter :\n"); scanf("%d",&n); printf("\nenter the numbers :\n"); for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n-1;i++) { for(j=0;j<n-1-i;j++) { if(a[j]>a[j+1]) { c=a[j]; a[j]=a[j+1]; a[j+1]=c; flag=0; } } if(flag) break; else flag=1; } printf("sorted elements :\n"); for(i=0;i<n;i++) printf("%d\t",a[i]); printf("\n"); } |
|