#include<stdio.h>
#include<conio.h>
int main()
{
int arr[10];
int i,j,k,tmp,num;
clrscr();
printf("Enter total no. of elements : ");
scanf("%d",&num);
printf("\nEnter elements : ");
for(k=0; k<num; k++)
{
scanf("%d",&arr[k]);
}
for(i=num/2; i>0; i=i/2)
{
for(j=i; j<num; j++)
{
for(k=j-i; k>=0; k=k-i)
{
if(arr[k+i]>=arr[k])
break;
else
{
tmp=arr[k];
arr[k]=arr[k+i];
arr[k+i]=tmp;
}
}
}
}
printf(" Array After Sorting Is: : \n");
for(k=0; k<num; k++)
printf("%d\t",arr[k]);
getch();
return 0;
}
#include<conio.h>
int main()
{
int arr[10];
int i,j,k,tmp,num;
clrscr();
printf("Enter total no. of elements : ");
scanf("%d",&num);
printf("\nEnter elements : ");
for(k=0; k<num; k++)
{
scanf("%d",&arr[k]);
}
for(i=num/2; i>0; i=i/2)
{
for(j=i; j<num; j++)
{
for(k=j-i; k>=0; k=k-i)
{
if(arr[k+i]>=arr[k])
break;
else
{
tmp=arr[k];
arr[k]=arr[k+i];
arr[k+i]=tmp;
}
}
}
}
printf(" Array After Sorting Is: : \n");
for(k=0; k<num; k++)
printf("%d\t",arr[k]);
getch();
return 0;
}
No comments:
Post a Comment