63 132
Assignments Done
99,1%
Successfully Done
In July 2018

Answer to Question #4717 in C++ for ROHAIL

Question #4717
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 USING
a) IF-ELSE STATEMENT
b) SWITCH STATEMENT
Expert's answer
#include<stdio.h>
main()
{

int last_digit, number, next_digit, rev_num;

printf ("Enter the five-digit number that has to be reversed and checked for equality:");

scanf("%d", &number);

last_digit = number - ((number / 10) * 10); /*units place*/

rev_num = last_digit; /* 5 */

next_digit = (number / 10) - ((number / 100) * 10); /*tenth's place*/

rev_num = (rev_num * 10) + next_digit; /*54*/

next_digit = (number / 100) - ((number / 1000) * 10); /*hundred's place*/

rev_num = (rev_num * 10) + next_digit; /*543*/

next_digit = (number / 1000) - ((number / 10000) * 10); /*thousand's place*/

rev_num = (rev_num * 10) + next_digit; /*5432*/

next_digit = (number / 10000) - ((number / 100000) * 10); /*ten thousand's place*/

rev_num = (rev_num * 10) + next_digit; /*54321*/

printf ("The Reversed Number is: %d",rev_num);

if (rev_num==number)

{
printf("\nEntered number and reversed number are equal\n");
}
else

{
printf("\nEntered number and reversed number are not equal\n");
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions