- 3

# C++

A palindromic number is a number (such as 626) that remains the same when its digits are reversed. Write a function that returns true if a given number is a palindrome, and false, if it is not. Complete the given function, so that the code in main works and results in the expected output.

4 Réponses

+ 2

🅰🅹 🅐🅝🅐🅝🅣
sorry, it's the typing mistake.

+ 1

Post your code first

0

Akash Singh
Do you think your code is right?
Why there is Semicolon (;) in if statement?

- 2

#include<iostream>
using namespace std;
bool palindrome(int n)
{ int temp,r,sum=0;
temp=n;
while(n>0)
{ r=n%10;
sum=(sum*10)+r;
n=n/10;
if(temp==sum)
return true;
else
return false;
}
void main()
{ int number;
cin>>number;
if(palindrome( number )==true)
cout<<"The number is palindrome.";
else
cout<<"The number is not palindrome.";
getch();
}
This the answer for your question, but firstly you have to try it yourself. Don't ask the questions directly.