This is the Bubble sort program for sorting the array in ascending order.
#include<stdio.h> void main(){ int i,j,indexofsmallest,temp,a[6],n=6; printf("enter your array \n"); for(i=0;i<=5;i++){ scanf("%d ",&a[i]); } for(i=0;i<n-1;i++){ for(j=0;j<n;j++){ if(a[j]>a[j+1]){ //swap temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } } //display for(i=0;i<6;i++){ printf("%d ",a[i]); }}
0 Comments