2023 5 11

xuxingkai / 2023-05-12 / 原文

#include<iostream>
using namespace std;
void pandaun(int a) {
    int i, t;
    t = a;//用于储存a的值
    int A[3];//用于储存各位上的数据
    for (i = 0; i < 3; i++) {
        A[i] = a % 10;
        a /= 10;
    }
    if (t == (A[0] * A[0] * A[0] + A[1] * A[1] * A[1] + A[2] * A[2] * A[2]))
        cout << t << "是水仙花数" << endl;
    //else { cout << t << "不是水仙花数" << endl; }
}
int main() {
    int low, heigh;//保证输入的数是三位数因为代码写的是三位数的
    cout << "请输入判断范围的上下限" << endl;
    cin >> low >> heigh;
    int j;
    for (j = low; j < heigh; j++) {
        pandaun(j);
    }
    return 0;
}