Dremendo Tag Line

Reverse 3 digit number in C++

cin - Question 8

In this question, we will see how to input a three digit number in C++ programming using the cin statement and reverse it. To know more about cin statement click on the cin statement lesson.

Q8) Write a program in C++ to input a three digit number and reverse it.

Input: 289
Reverse: 982

Program

#include <iostream>
#include <conio.h>

using namespace std;
int main()
{
    int n,fd,md,ld,rev;
    cout<<"Enter a three digit number\n";
    cin>>n;
    fd=n/100;
    md=(n/10)%10;
    ld=n%10;
    rev=ld*100+md*10+fd;
    cout<<"Reverse="<<rev;
    return 0;
}

Output

Enter a three digit number
326
Reverse=623
video-poster