Reverse the number

Write a program that reads a number and then to reverses the input number. Use loop and the division (/) operator and the remainder (%) operator.

#include<iostream>
using namespace std;
int main(){
	int a,b=0,c;
	cout<<"Enter the number : ";
	cin>>a;
	while(a){
		b = b*10;
		c = a%10;
		b = b+c;
		a = a/10;
	}
	cout<<"The reverse of the number is "<<b<<endl;
	return 0;
	
}
output of the above program. reverse of a number
output of the above program. reverse of a number

Leave a Reply