Thursday 25 July 2013

Chapter 2 solutions Problem [C](e)

Question-A five-digit number is entered through the keyboard. Write a
program to obtain the reversed number and to determine
whether the original and reversed numbers are equal or not.
Solution- 
it a copy of the program, we saw in last chapter except one argument, which is actually heart of the program. see the solution, if you are not able to solve this problem by your own.

#include<stdio.h>

int main()
{
int num,revnum=0,s,a;
printf("Enter any 5 digit Number\n");
scanf("%d",&num);
s=num; /* i am storing value of num in variable s */
a=s%10;
revnum=revnum+a*10000;
s=s/10;

a=s%10;
revnum=revnum+a*1000;
s=s/10;

a=s%10;
revnum=revnum+a*100;
s=s/10;

a=s%10;
revnum=revnum+a*10;
s=s/10;

a=s%10;
revnum=revnum+a;
s=s/10; /*optional argument */

if(revnum==num) 
printf("Both are equal\n");
else
printf("Both are unequal\n");
return 0;
/* check the condition of if ,I compared revnum with num, not with s  because value of  s reached to 0 after operations*/
}

No comments:

Post a Comment