repl.it
@justingraham/

Regional 2012 - Palindromic Numbers

C++

No description

fork
loading
Files
  • main.cpp
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <string>
#include <iostream>

using namespace std;

int main()
{
	int palindrome, reverse = 0;
	
	cout << "Enter a number:  ";
	cin >> palindrome;
	
	int num = 0, key = palindrome;
	for(int i = 1; palindrome != 0; i++)
	{
		num = palindrome % 10;
		palindrome = palindrome / 10;
		reverse = num + (reverse * 10);

	}

	if(reverse == key)
	{
		cout << key << " is a palindrome number";
	}
	else
	{
		cout << key << " is NOT a palindrome number";
	}
	
return 0;

}
Fetching token
?