Sunday 14 January 2018

Palindrome number

 Q : Write a program which asks for a integer from the user. It reverses the integer and prints “same” if after reversal the number is same as old number otherwise it prints “not same”.

Solution : 

/*==============================
     Girfa Student Help
     Program : Reverse a number
     More Program :http://girfahelp.blogspot.in/p/loop-c-language.html
================================*/
#include<stdio.h>
#include<conio.h>
void main()
{

     int n,m,r=0;
     clrscr();
     printf("Enter number>> ");
     scanf("%d",&n);
     m=n;
     while(n>0)

     {
          r=r*10+(n%10);
          n/=10;
     }
     if(r==m)
          puts("Same");
     else
          puts("Not Same");
     getch();

}

No comments:

Post a Comment