#include<stdio.h>
#include<conio.h>
#include<malloc.h>
int main()
{
int j,i,n,*arr,temp;
printf("\n Enter the number of elements ");
scanf("%d",&n);
arr=(int *)malloc(n*sizeof(int));
for(i=0;i<n;i++)
{
printf("\n Enter the element %d ",i);
scanf("%d",&arr[i]);
}
for(i=1;i<n;i++)
{
temp=arr[i];
j=i-1;
while(temp<arr[j] && j>=0)
{
arr[j+1]=arr[j];
j--;
}
arr[j+1]=temp;
}
printf("\n Sorted array is...... ");
for(i=0;i<n;i++)
printf("\t %d ",arr[i]);
getch();
return 0;
}
#include<conio.h>
#include<malloc.h>
int main()
{
int j,i,n,*arr,temp;
printf("\n Enter the number of elements ");
scanf("%d",&n);
arr=(int *)malloc(n*sizeof(int));
for(i=0;i<n;i++)
{
printf("\n Enter the element %d ",i);
scanf("%d",&arr[i]);
}
for(i=1;i<n;i++)
{
temp=arr[i];
j=i-1;
while(temp<arr[j] && j>=0)
{
arr[j+1]=arr[j];
j--;
}
arr[j+1]=temp;
}
printf("\n Sorted array is...... ");
for(i=0;i<n;i++)
printf("\t %d ",arr[i]);
getch();
return 0;
}
No comments:
Post a Comment
Convey your thoughts to authors.