intro to C Assume you have a int variable n that has already
intro to C:
Assume you have a int variable n that has already been declared and initialized . Its value is the number of integers that need to be read in from standard input and printed out in sorted (ascending) order, each on a line by itself. Furthermore, there are no duplicates in the input and every number to be read is a non-negative value that is less than n\'s value .
In this exercise you may not use any array . You may declare a variable or two as needed. With these restrictions, read the n values and print them out as required onto standard output .
Solution
#include <stdio.h>
//if n inputs are non-negative distinct integers
//which are less than n,
//then the inputs will always consist of
//the first n distinct non negative integers
//less than n (i.e 0 to n-1) in any order
//Sorting them would always output 0 to n-1 in order
int main()
{
int n = 6;
int a,i;
for(i=0;i<n;i++)
scanf(\"%d\", &a);
for(i=0;i<n;i++)
printf(\"\ %d\", i);
return 0;
}
---------------------------------------------------------------------------------------------------
Sample output
sh-4.2$ main
1
4
3
2
0
5
0
1
2
3
4
5
