Computer Science, asked by aahana95, 1 year ago

plzzz help me to understant this question it's urgent plzz tell me how to understand this question​

Attachments:

Answers

Answered by lastbenchstudent
1

here we are trying to reverse a number so we are using modulus of number

now what is modulus ?

modulus is same as getting remainder when we divide a number by another number. for example

18 % 4 = 2

or

18 mod 4 = 2

as when we divide 18 by 4 we get 2 as a remainder.

18 = 4×4 + 2

here i used % to show modulus which is used in many programming language.

so lets now come to question.

we are first getting last digit by doing modulus by 10.

as we can see

438 mod 10 = 8

so it gives us last digit.

now we are

multiplying last saved number by 10 and add this remainder. initilaly last saved number R is 0 so

new R = R ×10 + D = 0×10+8=8

now we change the number by dividing it by 10 so that we can get next digit.

new D = 438/10 = 43

now repeating above steps again

last digit D = 43 mod 10 =3

New R = old R ×10 + D

= 8×10 +3= 83

new number = 43/10 = 4

doing again as number is still greater than 0

last digit D= 4 mod 10 = 4

New R = old R ×10 + D= 83×10+4=834

new number 4/10 = 0

so now n is not greater than 0 so while loop stops here and we have the reveresed number 834


lastbenchstudent: Did you understand it ?
Similar questions
Math, 1 year ago