Detailed Explanation of Palindrome Number Program in C

In C language, a palindrome number is a number that is the same when reversed. For example, 121, 34543, 343, 131, and 48984 are all palindrome numbers.

Palindrome Number Algorithm

  • Get the number from the user

  • Store the number in a temporary variable

  • Reverse the number

  • Compare the temporary variable with the reversed number

  • If the two numbers are the same, output palindrome number

  • Otherwise, output non-palindrome number

👇Click to receive👇
👉C Language Knowledge Resource Collection

Let’s take a look at the palindrome number program in C. In this C program, we will get input from the user and check whether the number is a palindrome number.

#include <stdio.h>
int main() {  int n, r, sum = 0, temp;  printf("Please enter a number:");  scanf("%d", &n);  temp = n;
  while (n > 0) {      r = n % 10;      sum = (sum * 10) + r;      n = n / 10;  }
  if (temp == sum) {      printf("Palindrome");  } else {      printf("Non-palindrome");  }
  return 0;}

Output:

Enter a number: 151 Palindrome
Enter a number: 5621 Non-palindrome

Detailed Explanation of Palindrome Number Program in C


Recommended Hot Topics
  • C Language Tutorial – Detailed Explanation of Fibonacci Sequence in C

  • C Language Algorithm – “Combination Sum” Algorithm Problem

  • C++ Tutorial – Detailed Explanation of C++ Language Download and Installation

Leave a Comment