What is the value of m after executing the following code?
int n = 123456789;
int m = 0;
while (n != 0)
{
m = (10 * m) + (n % 10);
n = n / 10;
Answers
Answered by
0
Answer:
mn 10 nn 10 - Course Hero
int n = 123456789; int m = 0; while (n != 0) { m = (10 * m) + (n % 10); n = n / 10; } a. 0, 123456789 b. 987654321, 123456789 c. 987654321, 0 d. None of the above
Answered by
1
Question:-
Find the value of m after execution of the following code
Code:-
int n = 123456789;
int m = 0;
while (n != 0)
{
m = (10 * m) + (n % 10);
n = n / 10;
}
Output:-
987654321
Explaination:-
- This question is very easy, the code is exactly similar to reversing of the number.
- Each iteration, m is getting multiplied with 10 and the last digit of n is getting added to m and finally, the last digit gets removed when the control executes n=n/10
Similar questions