Algorithms_in_C++ 1.0.0
Set of 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:

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.

Function Documentation

◆ main()

int main ( void )

Main function

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}
T begin(T... args)
T end(T... args)
T reverse(T... args)
T to_string(T... args)
Here is the call graph for this function: