C Program 1 – To find the reversal of a given number
Assume the number 1234, after reversal the number becomes 4321.
Input: One number, Ex 1234, declared to num
Output : One number, Ex 4321, rev is the variable
- separate each digit using modulo operator from the right and bring that number to front
- divide the given number by 10, so the right most digit will be discarded.
- run till the number becomes <=0
output the result
printf("enter the number to be reversed");
while(num>0) //till the number is positive, perform the process
rev=rev*10 + (num%10); //separate each digit and bring it to the first
printf("The reversal is %d ",rev);