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<n;j++)
{
if(a[i]>a[j])
{
a[i]=a[i]+a[j];
a[j]=a[i]-a[j];
a[i]=a[i]-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<n;j++)
{
if(a[i]>a[j])
{
a[i]=a[i]+a[j];
a[j]=a[i]-a[j];
a[i]=a[i]-a[j];
}
}
}
for(i=0;i<n;i++)
printf("%d\n",a[i]);
}
No comments:
Post a Comment