+ 1

C++ palindrome number

How did i solve this program please give me the idea

23rd Mar 2021, 10:19 AM
vijayalakshmi T.G.
vijayalakshmi T.G. - avatar
13 Réponses
+ 8
vijayalakshmi T.G. Hii. Here is your code. #include <iostream> using namespace std; int main() { int a,b,s=0; cout << "Hii. Enter a number: "; cin >> a; b=a; while(a!=0){ s=s*10+a%10; a/=10; } if(s==b) cout << "Palindrome."; else cout << "Not Palindrome." return 0; }
25th Mar 2021, 5:19 AM
ᗩηιηɗуα ᗩɗнιкαяι
+ 2
U need to write here if condition after while if (reverse_num==digit)
23rd Mar 2021, 10:51 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 2
Martin Taylor I was unaware that it had to be strictly a function, my apologies XD. Anyway, it is easy to solve: bool ispalindrome (int num) { int dig, aux = 0, reves; aux = num; for (reves = 0; aux! = 0;) {dig = aux% 10; aux = aux / 10; reves = reves * 10 + dig; } if (reves == num) return true; else return false; }
24th Mar 2021, 5:53 AM
Julio Amaro
Julio Amaro - avatar
+ 2
This is my code, for checking given number is palindrome number or not #include <iostream> using namespace std; int main() { int n,temp,rev=0,d; cin >>n; temp=n; while(n!=0) { d=n%10; rev=rev*10+d; n=n/10; } if(temp==rev) { cout <<temp<<" is a palindrome"; } else { cout << temp<<" is NOT a palindrome"; } return 0; } This correct for the checking palindrome number or not
25th Mar 2021, 6:05 AM
Gunti Daniel Kumar
Gunti Daniel Kumar - avatar
+ 1
Show us the code so we can help
23rd Mar 2021, 10:23 AM
Soumik
Soumik - avatar
+ 1
vijayalakshmi T.G. Show as your code attempt.
23rd Mar 2021, 10:27 AM
Matias
Matias - avatar
+ 1
Although you can do it by converting the number into a string so as not to apply math, here is the math way to solve it https://code.sololearn.com/c0hIFL9T3slC/?ref=app
24th Mar 2021, 3:43 AM
Julio Amaro
Julio Amaro - avatar
+ 1
Ok thank you all👍
25th Mar 2021, 12:47 PM
vijayalakshmi T.G.
vijayalakshmi T.G. - avatar
0
bool ispalindrome (int x){ do { digit=x%10; rev=(rev*10)+digti; x=x/10; }while (x!=0); cout <<"The reverse of the number is:"<<rev<<endl;
23rd Mar 2021, 10:27 AM
vijayalakshmi T.G.
vijayalakshmi T.G. - avatar
0
Try my code it works:: #include <iostream> using namespace std; void isPalindrome(int x) { //complete the function int n = 0; int last; int w = x; while (x >0){ last = x%10; n = n*10 + last; x = x/10; } if (n == w){ cout <<w<<" is a palindrome"; } else { cout << w<<" is NOT a palindrome"; } } int main() { int n; cin >>n; isPalindrome(n); return 0; }
11th Jun 2021, 5:41 AM
Akshat Sharma