Monday, 7 March 2016

C Program to Check a Number is Palindrome or Not Using While Loop

Problem :- Write a C Program to Check Whether a Number is Palindrome or Not Using While Loop

Logic :- What Is Palindrome ?

"a word, phrase, or sequence that reads the same backwards as forwards"
" Matlab Ulta Seedha Ek Saman "

Simple if string is "12321" compare First '1' to Last '1' same continue repeat if all Number's are shame then Number Is Palindrome .If you understood what is palindrome then try to solve the given problem Check string is palindrome .

Try Yourself C++ Program To Check String Is Palindrome Or Not

Solution :-

#include<stdio.h>
int main()
{
//Ghanendra Yadav
int n, reverse=0, rem,temp;

printf("Enter an Integer To Check Number:\n");
scanf("%d", &n);
  
temp=n;
   
while(temp!=0)
{
rem=temp%10;
reverse=reverse*10+rem;
temp/=10;
}

   if(reverse==n)
       printf("%d is a Palindrome Number.",n);
   else
       printf("%d is Not a Palindrome Number.",n);
   return 0;
}

Output:-

C Program to Check a Number is Palindrome or Not Using While Loop

No comments:
Write comments

Recommended Posts × +