Algorithm to print reversed number.

Q8. Write an algorithm that allows a user to enter an integer value of upto 5 digits and prints the reversed number. (For example, if the user enters 4319 then the result should be 9134.)

Ans.

Integer num, mod, newnum;

newnum<-0;

print ‘Enter a number: ‘;

read num;

while(num)

//while(num>0)

{

mod<-number%10;

num<-num/10;

newnum<-(newnum*10)+mod;

}

print ‘The reversed number is: ‘,newnum;

Leave a Reply

Your email address will not be published. Required fields are marked *

112 Views
%d bloggers like this: