A palindrome is a number that is the same forward as it is backwards. Examples b
ID: 3674722 • Letter: A
Question
A palindrome is a number that is the same forward as it is backwards. Examples being 44, 202, 46364, etc... In Code:: Blocks, write a function called is Palindrome that takes in a 5 digit integer and checks whether or not it is a palindrome. If it is, the function should print out "Yes" to the console, else it should print out "No". Inside the main function, write a prompt asking the user for the 4 digit integer and pass that value into the function. Use what you know about the % and/operators. Submit the source file as palindromes.cpp on Blackboard before the time is up.Explanation / Answer
#include <iostream>
using namespace std;
void isPalindrome(int n){
int a[5];
for(int i =0 ;i<5;i++){
a[i] = n % 10;
n = n / 10;
}
if(a[0] == a[4] && a[1] == a[3])
cout<<"Yes";
else
cout<<"No";
}
int main(){
int n;
cout<<"Enter the 5 digit number ";
cin>>n;
isPalindrome(n);
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.