C program to check number is palindrome

devquora
devquora

Posted On: Jan 26, 2023

C program to check number is palindrome

 

Overview:

As we know that time is the most important concern in our life. To do any task easily, We have to use software to perform it in a simpler manner. Software is a set of programs with related documents. The Software Program or Program is a set of instructions to do a specific task. Here, our specific task is to check number is palindrome or not. First, I want to explain What is number? Then, I will explain What do you mean by Reverse? and what is positive integer? Moreover, I will explain What is a palindrome? Moreover, I will demonstrate how to check a number is palindrome or not? After all, I will write the logic of a C program to check number is palindrome and explain it with output.

Table of contents:

  1. What is a string?
  2. What is a number?
  3. What is a positive integer?
  4. What do you mean by Reverse?
  5. What is palindrome?
  6. Demonstration to check a number is it palindrome or not.
  7. Logic to check if a number is palindrome or not
  8. C program to check number is palindrome
  9. Explanation of the C program to check number is palindrome with output.
  10. Conclusion

What is a String?

The String is a combination of characters that may be any digit from 0 to 9 and Alphabets from A to Z. The repetition of characters does not matter. For instance, a String Conax uses 5 characters i.e. C,o,n,e,and x.

What is a number?

A number is also a string but only included digits, decimal point and some mathematical signs such as -, +, i etc. Number is an object that uses digits to perform mathematical task. Calculus that is a branch of mathematics included many numbers such as integer, whole number, real number, and imaginary numbers so on. Here, I will discuss about number who has palindrome. Moreover, Number is a combination of digits, some symbols and decimal point. Forthermore, A positive integer is a combination of digits only. For instance, 323 is a positive integer.

What is a positive integer?

A positive integer is a combination of digits only. It is also known as natural number. A sequence from 1 to infinite is known as natural number sequence. For instance, 323 is a positive integer.

What do you mean by Reverse?

Reverse means move backward and turned toward the direction opposite to that previously stated. For instance, If our number is 321 then its reverse string is 123.

What is a Palindrome?

An integer is a palindrome if the reverse of that number is equal to the original number. In other words, A Palindrome is an approach in which the reversed string is the same as the previous string. For instance, the Reverse of a number 323 is also 323. So we can say that 323 is a palindrome.

Demonstration to check a number is it palindrome or not

Demo of palindrome

Logic to check a number is it palindrome or not

  • Step 1: The user is asked to enter an integer. The number is stored in variable n.
  • Step 1: We then assigned this number to another variable orignalN.
  • Step 2: Then, the reverse of n is found by reversed technique and stored it in reversedN.
  • Step 3: If originalN is equal to reversedN, the number entered by the user is a palindrome.

C program to check number is palindrome

#include <stdio.h>
int main() {
    int n, reversedN = 0, remainder, originalN;
    printf("Please! 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;
}

The output of the Program with code:

Explanation of the C program to reverse a string with output

c program to check number is palindrome

 

Conclusion:.

In the successful compilation of the program, a message is displayed on the screen as Please! Enter an integer:

This program entered a number by user then store it into a variable after that found its reversed and store it in to another variable if both variables are equal then we can say that inputed number is palindrome otherwise that is not a palindrome.

    Please Login or Register to leave a response.

    Related Articles

    C Program Examples

    C Program to convert Decimal to Binary Number

    A Decimal Number is constructed with any digit from 0 to 9. For instance, 24 is a Decimal Number constructed from the digits 2 and 4. A Binary Number is constructed with digits 0 and 1. For instance, ..

    C Program Examples

    C program to reverse a string

    This program reversed the entered string that means opposite of the previous string sequence...

    C Program Examples

    C program to reverse an Integer number

    Are you want a demonstration of The C Program that reverses an Integer number? This Program reversing the sequence of digits in an Integer. After the successful compilation of the program, a message..