#include<stdio.h> int main(){ int i,j,num,temp,a[20]; printf("Enter total elements: "); scanf("%d",&num); printf("Enter %d elements: ",num); for(i=0;i<num;i++) scanf("%d",&a[i]); for(i=1;i<num;i++){ temp=a[i]; j=i-1; while((temp<a[j])&&(j>=0)){ a[j+1]=a[j]; j=j-1; } a[j+1]=temp; } printf("After Sorting: "); for(i=0;i<num;i++) printf("%d",a[i]); return 0; }
Output :
Enter total elements: 5 Enter 5 elements: 9 4 1 0 2 After sorting: 0 1 2 4 9
No comments:
Post a Comment