Professional Documents
Culture Documents
Members’ Information................................................................................. 3
Problem........................................................................................................ 4
Objective...................................................................................................... 4
Flowchart...................................................................................................... 5
Code Program............................................................................................... 6
Program Screen............................................................................................ 7
Reference..................................................................................................... 8
2
MEMBERS’ INFORMATION
3
PROBLEM
Write a program to reverse the digits of a positive integer number. For example, if the 1708
is entered, the number displayed should be 8071. (Hint: use a do statement and
continuously strip off and display the unit digit of the number. If the variable num initially
contains the number entered, the unit digit is obtained as (num % 10). After a unit digit is
displayed, dividing the number by 10 sets up the number for the next iteration. Thus, (1708
% 10) is 8 and (1708 / 10) is 170. The do statement should continue as long as the remaining
number is not zero.)
OBJECTIVE
4
FLOWCHART
Start
reverse = 0
Enter number
If no > 0
No
Yes
digit = no % 10
reverse = reverse * 10 + digit
no = no / 10
no != 0
Yes
No
End
5
CODE PROGRAM
#include<iostream>
int main()
int reverse=0,no,digit;
cout<<"Enter no = ";
cin>>no;
if(no>0)
do
digit=no%10;
reverse=reverse*10+digit;
no=no/10;
while(no!=0);
cout<<"Reverse no = "<<reverse<<endl;
system("pause");
6
PROGRAM SCREEN
SAMPLE INPUT
SAMPLE OUTPUT
7
REFERENCE