(CANNOT USE ARRAY AND ONLY CAN USE WHILE LOOPS) Write a C++ program that asks the user to enter a positive integer n and then that reads n user input integers and finally prints the message The numbers you entered are in increasing order if they are in increasing order or the message The numbers you entered are NOT in increasing order if they are not. See the remark below. Remark:- Remember given the numbers a1, a2, a3, ..., an; we say they are in increasing order if a1 ≤ a2 ≤ a3 ≤ .... ≤ an. Moreover remember that if you have only one number from the user input then the number automatically is in increasing order.
(CANNOT USE ARRAY AND ONLY CAN USE WHILE LOOPS)
Write a C++ program that asks the user to enter a positive integer n and then that reads n
user input integers and finally prints the message The numbers you entered are in
increasing order if they are in increasing order or the message The numbers you entered
are NOT in increasing order if they are not. See the remark below.
Remark:- Remember given the numbers a1, a2, a3, ..., an; we say they are in increasing order
if a1 ≤ a2 ≤ a3 ≤ .... ≤ an. Moreover remember that if you have only one number from the
user input then the number automatically is in increasing order.
#include<iostream>
using namespace std;
int main(){
int n,t1,t2,i=0;
// Assume the list is in Strictly increasing by default
bool result=true;
// read all the values
cout<<"Enter a Positive Number : ";
cin>>n;
cout<<"Enter "<<n<<" Elements : ";
while(i<n){
cin>>t2;
if(i==0)
t1=t2;
// If the previous number is greater than first
// then list is in decreasing order
if(t1>t2){
result=false;
}
t1=t2;
i++;
}
// print the result
if(!result)
cout<<"The Numbers you entered are not in increasing order ";
else
cout<<"The Numbers you entered are in increasing order ";
}
Step by step
Solved in 2 steps with 3 images