+ 2


Pls may i know why I don’t get the output #include <iostream> using namespace std; int main() { int n,n1,n2=n,rev=0; cout<<"Enter any number"; cin>>n; while(n) { n1=n%10; rev=rev*10+n1; n=n%10; } if(n2==rev) { cout<<"num is palindrome";} else { cout<<"num is not palindrome";} return 0; }

2nd Jan 2019, 10:49 AM
Jothika - avatar
2 Answers
+ 1
1. Change n=n%10 to n=n/10. Otherwise, the value of n never changes and the code is stuck in an infinite loop. 2. Declare n2=n after cin>>n; Otherwise, an error will be thrown for the n2 variable since n hasn't been initialised yet. https://code.sololearn.com/caiJ316bTBL4/?ref=app
14th Jan 2020, 3:30 PM
silentlearner - avatar
error in code, while loop runs infinitely if the number n does not end at 0
2nd Jan 2019, 11:12 AM
Игорь Яковенко
Игорь Яковенко - avatar