Wednesday, April 8, 2015

31. Write a program to enter 'n' numbers into one dimensional array and sort and display them in ascending order.


#include<stdio.h>
#include<conio.h>
void main()
{
int num[100],i,j,n,temp;
clrscr();
printf("\n How many data:-");
scanf("%d",&n);
printf("\n input %d data's:- ",n);
for(i=0;i<n;i++)
{
printf("\n num[%d]:-",i);
scanf("%d",&num[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(num[i]>num[j])
{
temp=num[i];
num[i]=num[j];
num[j]=temp;
}
}
}
printf("\n The data in ascending orders are:\n");
for(i=0;i<n;i++)
{
printf("%5d", num[i]);
}
getch();
}

No comments:

Post a Comment