main()
{
int a[50],i,j,n;
printf("Enter the no. of elements");
ab:
scanf("%d",&n);
if(n>50)
{
printf("limit exceeded \nPlease enter again");
goto ab;
}
for(i=0;i<n;i++)
{
printf("enter %d element \n",i+1);
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j>0;j--)
{
if(a[j-1]<a[j])
break;
if(a[j-1]>a[j])
{
a[j-1]=a[j-1]+a[j];
a[j]=a[j-1]-a[j];
a[j-1]=a[j-1]-a[j];
}
}
}
for(i=0;i<n;i++)
printf("%d\n",a[i]);
}
{
int a[50],i,j,n;
printf("Enter the no. of elements");
ab:
scanf("%d",&n);
if(n>50)
{
printf("limit exceeded \nPlease enter again");
goto ab;
}
for(i=0;i<n;i++)
{
printf("enter %d element \n",i+1);
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j>0;j--)
{
if(a[j-1]<a[j])
break;
if(a[j-1]>a[j])
{
a[j-1]=a[j-1]+a[j];
a[j]=a[j-1]-a[j];
a[j-1]=a[j-1]-a[j];
}
}
}
for(i=0;i<n;i++)
printf("%d\n",a[i]);
}
No comments:
Post a Comment