why we write …?
N=N-1
IN THIS CODE
#include
using namespace std;
int main(){
int N;
cin>>N;
int no;
while(N>0){
cin>>no;
cout<<no*no<<endl;
N=N-1;
}
return 0;
}
why we write …?
N=N-1
IN THIS CODE
#include
using namespace std;
int main(){
int N;
cin>>N;
int no;
while(N>0){
cin>>no;
cout<<no*no<<endl;
N=N-1;
}
return 0;
}
while(N>0){
cin>>no;
cout<<no*no<<endl;
N=N-1;
}
As you while loop will execute until and unless the value of N is greater then 0, so if value of n is bigger then 0, then we have to decrement it and that’s why we are using N = N-1 that means , if value of n is 3 then after one execution value of n will be 2 and so on until it’s value become equal to or greater then 0.
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.