Reverse the number without using loop in c++

In this section you will learn how to reverse the numbers in c++ without using loop. We will use two variable for reverse the numbers. Just simple mathematic operation we will perform to reverse the number. In this program we are taking the input from user.

Reverse mean shifting the first value to last value and shifting the last value to first value.

Let’s suppose a user will input a number ‘386’, then we will perform reverse operation on it.

How program will work?

Program of reverse three digit number without using loop in c++.


	#include<iostream.h>
	#include<conio.h>
		
	//PROGRAM OF REVERS THREE DIGIT NUMBER WITHOUT LOOP
	void main()
	{
		int num, temp;
		clrscr();
		
		cout<<"ENTER THE THREE DIGIT NUMBER:- ";
		cin>>num;
		
		cout<<"AFTER REVERSE RESULT IS:- ";
		temp = num%10;
		cout<<temp;
		temp = num/10;
		temp = temp%10;
		cout<<temp;
		temp = num/10;
		temp = temp/10;
		cout<<temp;

		getch();
	}
	

Output:


	ENTER THE THREE DIGIT NUMBER:- 386
	AFTER REVERS NUMBER IS:- 683

Post Your Comment