+ 1
where shoud i place "i" to save "n" value in this code and can show the saved amount of "n" in the last line?
#include <iostream> using namespace std; int main() { int n, s=0,a,i; i=n; cin>>n; while(n>0) { a=n%10; s=s*10+a; n=n/10; } cout<<"enter n"<<i<<":"<<s; return 0; }
3 Respuestas
+ 2
The program is read and executed from top to bottom, therefore assigning 'n' to 'i' when neither of them has been initialized with a value is basically worthless. You first need to get the value of 'n' from the user before being able to copy it into 'i'.
+ 1
Ok Shadow but what should i do if i need to save the amount of so called 'n' and then show it in the output.
+ 1
Firstly ask the user to enter n value with cout<<"Enter n"<<endl;
Then use cin>>n;
Then assign n to i or i to n i=n; then do the while looping.And finally cout<<i<<s;