Assignment - 7
Assignment - 7
Solution:
Algorithm:
1) Start
2) Prompt the user to input an integer.
3) Initialize a variable reverse = 0.
4) Repeat while the number num is greater than 0:
a. Extract the last digit: remainder = num % 10.
b. Append it to reverse: reverse = reverse * 10 + remainder.
c. Remove the last digit from num: num = num / 10.
5) Output the reversed number.
6) Stop
Code:
Output:
echo -n "Enter an integer: "
read num
reverse=0
Discussion: It takes an input number from the user and reverses its digits using basic
arithmetic operations and a while loop.