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