Computer Science, asked by pratisthashinchan, 7 months ago

write a program in java to find the reverse of three digit number.​

Answers

Answered by DHAVALS9429
1

Answer:

Please Mark To Brainliest

Explanation:

In this program, while loop is used to reverse a number as given in the following steps:

First, the remainder of the num divided by 10 is stored in the variable digit. Now, the digit contains the last digit of num, i.e. 4.

digit is then added to the variable reversed after multiplying it by 10. Multiplication by 10 adds a new place in the reversed number. One-th place multiplied by 10 gives you tenth place, tenth gives you hundredth, and so on. In this case, reversed contains 0 * 10 + 4 = 4.

num is then divided by 10 so that now it only contains the first three digits: 123.

After second iteration, digit equals 3, reversed equals 4 * 10 + 3 = 43 and num = 12

After third iteration, digit equals 2, reversed equals 43 * 10 + 2 = 432 and num = 1

After fourth iteration, digit equals 1, reversed equals 432 * 10 + 1 = 4321 and num = 0

Now num = 0, so the test expression num != 0 fails and while loop exits. reversed already contains the reversed number 4321.

Answered by MRVarsha
0

#include <stdio.h>

int main()

{ int n, num1,num2,num3, reverse;

printf("Enter the number to reverse:\n");

scanf("%d", &n);

num1 = n / 100;

num2 = (n % 100) / 10;

num3 = (n % 10) / 100;

reverse = num3*100+ num2*10;

printf(" The reverse is %d", reverse);

system("pause"); return 0;}

Hope this helps you...

Please don't forget to mark the answer as brainiest and follow me mate...

Similar questions