Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

LANGUAGE: C. Assume you have a int variable n that has already been declared and

ID: 3820708 • Letter: L

Question

LANGUAGE: 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 .

Explanation / Answer

Ans: I have done in a simple way.

#include <iostream>
using namespace std;
int main()
{
int n = 10, inpt;
for( int i = 0; i < n; i++ )
cin >> inpt;
for( int i = 0; i < n; i++ )
cout << i << endl;
return 0;
}
EXPLANATION:
In the above code, it reads in the n number of integers. Then it displays to the console integers in the range 0 to n-1. The problem says "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.". Since there are no duplicates and all numbers are less than n all you need to do is display 0 to n-1.