Write C++ that
(1)Convert the inputted 3-digit integer, the single digit to a hundred digit, and the hundreds digit to a single digit, and generate a new inverted number from the converted 3 digits.
(2) Arbitrary 3-digit integers are input by keyboard.
(3) When outputting the result, the required form is: original number: converted number.
4)run test the code in main
#include <iostream>
#include<cmath>
using namespace std;
int main(){
int n,b,c,a;
cout<<"Enter 3 digit number"<<endl;
cin>>n;
a=trunc(n/100);
b=n-a;
b=trunc(b/10)-a*10;
c=n-(100*a)-(10*b);
cout<<a<<endl;
cout<<b<<endl;
cout<<c<<endl;
int number=c*100+b*10+a;
cout<<"Old number="<<n<<endl;
cout<<"New inverted number="<<number<<endl;
return 0;
}
Comments
Leave a comment