#include <stdio.h> #include <stdlib.h> int main() { int data[5]={14,33,27,35,10}; int i,j; int swap; int temp; for(int i=0;i<5;i++) { printf("please enter array element %d: ",i+1); scanf("%d",&data[i]); } for(int i=0;i<5-1;i++) { swap=0; for(int j=0;j<5-1;j++) { if(data[j]>data[j+1]) { temp=data[j]; data[j]=data[j+1]; data[j+1]=temp; } } } printf("bubble sort of array are: "); for(int i=0;i<5; i++) { printf("%d ",data[i]); } printf("\n"); return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter