Increasing decreasing sequence

Sir how do i break a sequence of nos without storing it
i have just input a sequence with the code:
#include
using namespace std;
int main()
{
int n,no;
cin>>n;
while(n>0)
{
cin>>no;
n=n-1;

}
return 0;

}

Hi @Megha2468
For that you have to include a if condition in you while loop and in if condition add break; statement which will move you out of the while loop.

sir how to compare two nos when I am not storing them

@Megha2468
In your code if you are using only n as variable then you need to compare it with an integer value like 0 or 1.
For example if you want to take input until you encounter 0 as input then you can use :
if(n==0){
break;
}

sir I am not having problem in taking input but in the sequence I need to compare nos like i have input 2
3
4
5
how do I go back and compare 2 and 3
3 and 4 as i have not stored them

@Megha2468
You can compare 3 variables at a time by taking a var x in while loop as :
while(n>0){
int x=n; // storing previous value of n
cin>>n; // taking input of new n
compare(x,n); // comparing previous and current value of n
x=n; // storing current value of n in x
cin>>n; // taking new input
compare(x,n); // comparing current and next value of n
}

Similarly you can compare as many as input in a single go but have to store them in a variable.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.