Submit palindrome.cpp for problem 1 and collatz.cpp for problem 2. Problem 1: (P
ID: 3826663 • Letter: S
Question
Submit palindrome.cpp for problem 1 and collatz.cpp for problem 2. Problem 1: (Palindrome) A palindromic number or numeral palindrome is a number that remains the same when its digits are reversed. Write a program that checks whether a nonnegative integer is a palindromic number. The input and output should be exactly Input a nonnegative integer: CUSER ENTERS A NONNEGATIVE INTEGER) followed by X is a palindromic number. X is not a palindromic number. where X is the integer provided by the user. You may not use any libraries aside from iostream Name your file palindrome cpp. Hint. The code int i 4578 int j; for (j i (j/10) 0 j 10) cout j endl extracts the leading digit 4. This code is written cryptically and in poor style for pedagogical purposes. Please don't write code this way.Explanation / Answer
# Program
#include <iostream>
using namespace std;
int main()
{
int n, num, digit, rev = 0;
cout << "Enter a positive number: ";
cin >> num;
n = num;
do
{
digit = num % 10;
rev = (rev * 10) + digit;
num = num / 10;
} while (num != 0);
if (n == rev)
cout << n <<" is a palindrome number" << endl;
else
cout << n <<" is not a palindrome number" << endl;
return 0;
}
Output :
h-4.2$ g++ -o main *.cpp
sh-4.2$ main
Enter a positive number: 535
535 is a palindrome number
sh-4.2$ main
Enter a positive number: 534
534 is not a palindrome number
sh-4.2$ main
Enter a positive number: 100000001
100000001 is a palindrome number