(C++) CPP Programs - 7

Friday, December 14, 2007

7. Write a C program to reverse a given number and check whether it is Palindrome or not. Output the given number with suitable message.

/* Reverse a number*/

#include

#include

void main()

{

int n,digit,rev=0,temp;

clrscr();

printf("Enter an number\n\a");

scanf("%d",&n);

temp=n;

while(n!=0)

{

digit=n%10;

rev=rev*10+digit;

n=n/10;

}

printf("The reversed number is=%d\n\a",rev);

if(rev==temp)

printf("The given number is palindrome\n\a",temp);

else

printf("The given number is not a palindrome\n\a");

getch();

}

0 comments:

Post a Comment

Chitika

About This Blog

Followers

Blog Archive

  © Blogger template The Professional Template II by Ourblogtemplates.com 2009

Back to TOP