You are viewing a single comment's thread. Return to all comments →
int main() { int a[2000000],i,j,n,temp,swap=0,c,d; scanf("%d",&n); for(i=0;i
} for(i=1;i<n;i++) { for(j=0;j<n-i;j++) { if(a[j]>a[j+1]) { temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; swap++; } } } c=a[0]; d=a[n-1]; printf("Array is sorted in %d swaps.\n",swap); printf("First Element: %d\n",c); printf("Last Element: %d\n",d);
return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Sorting: Bubble Sort
You are viewing a single comment's thread. Return to all comments →
include
int main() { int a[2000000],i,j,n,temp,swap=0,c,d; scanf("%d",&n); for(i=0;i
return 0; }