Write a C program to take input for a number, if the number is palindrome, then display
its half on the screen, otherwise take
input for 2 more numbers, and display their product
on the screen. Use minimum two functions including main function
Answers
Explanation:
Programiz
Search Programiz
Get C Mobile App
C Program to Check Whether a Number is Palindrome or Not
In this example, you will learn to check whether the number entered by the user is a palindrome or not.
To understand this example, you should have the knowledge of the following C programming topics:
C Programming Operators
C if...else Statement
C while and do...while Loop
An integer is a palindrome if the reverse of that number is equal to the original number.
Program to Check Palindrome
#include <stdio.h>
int main() {
int n, reversedN = 0, remainder, originalN;
printf("Enter an integer: ");
scanf("%d", &n);
originalN = n;
// reversed integer is stored in reversedN
while (n != 0) {
remainder = n % 10;
reversedN = reversedN * 10 + remainder;
n /= 10;
}
// palindrome if orignalN and reversedN are equal
if (originalN == reversedN)
printf("%d is a palindrome.", originalN);
else
printf("%d is not a palindrome.", originalN);
return 0;
}