Palindrome Number

Palindrome Number

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn C programming concepts. You can learn C language at your own speed and time. One can learn concepts of C language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Palindrome Number
Palindrome Number

Write a C program to Palindrome Number

PROGRAM: Palindrome Number

/* Palindrome number using while loop */
#include <stdio.h>
int main()
{
 int n, r = 0,t;
 
 printf("Please enter a number: ");
 scanf("%d",&n);

 t=n;
 while (n > 0)
 {
  r = r * 10;
  r = r + n%10;
  n = n/10;
 }
 
 if(t==r)
  printf("Number is Palindrome");
 else
  printf("Number is not Palindrome");
  
 return 0;
}

------------------------------------------------------------------

/* Palindrome number using for loop */
#include <stdio.h>
int main()
{
 int n, r, t;
 
 printf("Please enter a number: ");
 scanf("%d",&n);
 
 t=n;
 for(r=0;n>0;n=n/10)
 {
  r = r * 10;
  r = r + n%10;
 }
 
 if(t==r)
  printf("Number is Palindrome");
 else
  printf("Number is not Palindrome");
  
 return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *