TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
Loading...
Searching...
No Matches
palindrome_of_number.cpp File Reference

Check if a number is palindrome or not. More...

#include <algorithm>
#include <iostream>
#include <cstring>
Include dependency graph for palindrome_of_number.cpp:

Go to the source code of this file.

Functions

int main ()
 

Detailed Description

Check if a number is palindrome or not.

This program cheats by using the STL library's std::reverse function.

Definition in file palindrome_of_number.cpp.

Function Documentation

◆ main()

int main ( void )

Main function

Definition at line 19 of file palindrome_of_number.cpp.

19 {
20 int num;
21 std::cout << "Enter number = ";
22 std::cin >> num;
23
24 std::string s1 = std::to_string(num); // convert number to string
25 std::string s2 = s1;
26
27 std::reverse(s1.begin(), s1.end()); // reverse the string
28
29 if (s1 == s2) // check if reverse and original string are identical
30 std::cout << "true";
31 else
32 std::cout << "false";
33
34 return 0;
35}