BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan

BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan (http://bzupages.com/)
-   Object Oriented Programming (http://bzupages.com/322-object-oriented-programming/)
-   -   Program to enter an integer and output it in the reversed form (http://bzupages.com/f322/program-enter-integer-output-reversed-form-14657/)

bonfire 08-03-2011 11:59 PM

Program to enter an integer and output it in the reversed form
 
1 Attachment(s)
Program to enter an integer and output it in the reversed form


#include
#include

void main()
{
clrscr();
long int num1,num2,rnum=0;
cout << "Enter an integer : " << endl;
cin>>num1;
num2=num1;
do
{
rnum=rnum*10;
int digit=num1%10;
rnum+=digit;
num1/=10;
}
while(num1);
cout << "The integer you typed is " << num2 << "." << endl;
cout << "The reversed integer is " << rnum << "." << endl;
getch();
}
This program takes in an integer num1 as a screen input from the user.
It then outputs the integer in its reversed form using the 'cout' command.

Sample Input
987
Sample Output


The integer you typed is 987.
The reversed integer is 789.


All times are GMT +5. The time now is 03:00 PM.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.