C语言C++判断输入内容

img


#include <iostream>
using namespace std;

int main()
{
        int a;
        cin >> a;
        if(a>=0 && a<=9)
        {
                cout << a << "是1位数" << endl;
                cout << "每一位上的数字是" << a << endl;
                cout << "逆序数是" << a << endl;
        }
        else if(a>=10 && a<=99)
        {
                cout << a << "是2位数" << endl;
                int x1 = a/10;  //十位
                int x2 = a%10;  //个位
                cout << "每一位上的数字是" << x1 << x2 << endl;
                int sum = x2*10 + x1;
                cout << "逆序数是" << sum << endl;
        }
        else if(a>=100 && a<=999)
        {
                cout << a << "是3位数" << endl;
                int y1 = a/100;
                int y2 = a%100/10;  //*除掉100就剩余下的一个两位数了,除掉10 刚好是十位数上的数字,前面int整形所以只输出整数,从而达到,输出十位数上的数字的效果
                int y3 = a%100%10;   //
                cout << "每一位上的数字是" << y1 << y2 << y3 << endl;
                int num = y3*100 + y2*10 + y1;
                cout << "逆序数是" << num << endl;
        }

        return 0;
}