C Program to Check Given Number is Palindrome or Not

Ex: write a C program to check given number is palindrome or not. How to write a C program to check given number is palindrome or not. C Program to check given number is palindrome or not.


Input from user:


Enter the number: 12321


Expected output:

Given number is palindrome.





   Step by step logic of the given program:



1. Accept input (number) from user.

2. After that use one while loop to check given number is greater than zero or not.

3. If number is greater than 0 then while loop will iterate.

4. Use reverse number logic inside the loop to calculate reverse number.

reverse=reverse*10; reverse=reverse+(no % 10);
no=no/10;

5. After that using if statement check condition
if(reverse==num)

6. Then print given number is palindrome. Otherwise print given numbers is not palindrome.





   C program to check given number is palindrome or not:

#include<stdio.h>
int main()
{
int no,num,reverse=0;

    printf("Enter the number:");
    scanf("%d",&no);
    num=no;
    
   while(no!=0)
    {
reverse=reverse*10; reverse=reverse+(no % 10);
no=no/10;   
    }    
    if(reverse==num)
    {
    printf("Given number is palindrome");
    }
    else
    {
    printf("Given number is not palindrome");
    }
    
    return 0;

}



Above prgram shows the following output:



No comments:

Post a Comment

If you have any doubts, please discuss here...👇