8.8k views
1 vote
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 (or fancy STL collection such as a vector). 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.

User MarkyRoden
by
6.7k points

1 Answer

4 votes

Answer:

/*This program is in c++*/

# include<iostream>

#include<stdio.h>

using namespace:; std;

int main()

{

int n, a[20]; /* n can be maximum 20*/

cout<<"Enter the value of n";

cin>>n;

For (int i=0;i<=n;i++)

{

cout<<"The number must be less than"<<n;

cin>>a[i];

}

int k=a[0];

for(int j=0;j<=n;j++)

{

if(a[i]<k)

{

a[i];=k

k=a[i];

}

else

{

continue;

}

}

cout<<"The numbers in ascending order are:";

for{int m=0;i<=n;i++)

{

cout<<"a[i];

}

return 0;

}

Step-by-step explanation:

The program is self explanatory.

User Afridi Kayal
by
5.8k points