Write a C Program to check a number is Palindrome or not





palindrome, C, Timus Rak, Sumit Kar





/*Using While loop*/





#include <stdio.h>

void main()

{

 int n, r = 0,t;


 printf("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");


}








/*Using For loop*/







#include <stdio.h>


void 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");


  


}



Comments

Popular posts from this blog

Write a Program to Add two 3x3 Matrix using C

C program for Unit Conversion

Write a Program to Add two 5x5 Matrix using C