Fun with Palindromic Numbers and Words in C++.

Finding whether a word or number is a palindrome is very common in programming languages. A palindrome word or number is one that reads the same in either direction. Words: bob, boob, ana… Numbers: 1, 2, 33, 121, 222, 3445443.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <string>
using namespace std;
//finding palindromes
int main()
{
	cout << "Enter word or number: ";
	string temp, input; cin >> input;
	temp = input;
 
	reverse(input.begin(), input.end());//reversing input
	if(temp == input) { cout << temp << " is a palindrome!" << endl; } //checking for palin
	else { cout << temp << " is not a palindrome!" << endl; }
 
	system("pause");
	return 0;
}
Share This!

Leave a Reply

Your email address will not be published.