Pages

Ads 468x60px

Saturday, 2 June 2012

C Program For ORDER OF NUMBERS.




C Program For ORDER OF NUMBERS.



I have an assignment in which I am supposed to write a code that will prompt the user to enter three integers, and then it should print out the numbers in ascending order. My teacher said that we should use scanf three times, and I'm not sure if that means we HAVE to but I just realized that I didn't do that in my code





CODE:
/* N=321 AND RESULT=123*/ 


#include<stdio.h>
#include<conio.h>
void main()
{
int n,t,z=1,i,j,a[20];
clrscr();
printf("Enter any number:");
scanf("%d",&n);
while(n>0)
{
t=n%10;
a[z]=t;
z++;
n=n/10;
}
for(i=1;i<=z;i++)
{
for(j=i+1;j<=z;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
for(i=2;i<=z;i++)
{
printf("%d",a[i]);
}
getch();
}

0 comments:

Post a Comment

Total Pageviews