mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
Added and algorithm to check if a number is palindrome
Added the algorithm to convert number to string and check if it's a palindrome.
This commit is contained in:
parent
16e1bcdb52
commit
227dcf0525
20
Palindromeofnumber.cpp
Normal file
20
Palindromeofnumber.cpp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include<bits/stdc++.h>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int num;
|
||||||
|
cin>>num;
|
||||||
|
|
||||||
|
string s1 = to_string(num);
|
||||||
|
string s2 = s1;
|
||||||
|
|
||||||
|
reverse(s1.begin(),s1.end());
|
||||||
|
|
||||||
|
if(s1==s2)
|
||||||
|
cout<<"true";
|
||||||
|
else
|
||||||
|
cout<<"false";
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user