I was asked to write a program that prompts the user to enter a 3-digit number, the program flips & displays the number.
for example: input (286) .. output (682)
input (690)... output (96)---> without the (0)
my program works well when inputting an integer that doesn't have a zero at the end of it (e.g. 286) but when I input (690) it displays (096) and not (96).
what should I add to my code in order to prevent the program from displaying the 0.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include<iostream>
usingnamespace std;
int main()
{
int n1, rn1, n2, n3, num;
cout<<"Enter a 3-digits postive integer: ";
cin>> num;
n1 = num/100;
rn1 = num%100;
n2 = rn1/10;
n3 = rn1%10;
cout<<"The flipped value of "<<num<<" is "<<n3<<n2<<n1;
return 0;
}
Your math is wrong. Don't forget you need to multiply each digit by the place you want it to be in. For example, to get a digit in the hundreds place you need to multiply it by 100.