Find the first positive integer n among three digits that satisfies the following requirements, in which the sum of the cubes of each digit is exactly equal to itself

Such as: 371=3^3+7^{3}+1^{3}

#include<stdio.h>
int main(void) {
    for (int i = 100; i < 1000; i++)
    {
        int a = i % 10;//提取个位上的数
        int b = i / 10 % 10;//提取十位上的数
        int c = i / 100;//提取百位上的数
        if (i == a * a * a + b * b * b + c * c * c) {
            printf("%d\n", i);
        }

    }
    return 0;
}

running result:

 

The power can also be expressed like this: Here you need to introduce the header file math.h

#include<stdio.h>
#include<math.h>
int main(void) {
    for (int i = 100; i < 1000; i++)
    {
        int a = i % 10;//提取个位上的数
        int b = i / 10 % 10;//提取十位上的数
        int c = i / 100;//提取百位上的数
        if (i == pow(a,3)+pow(b,3)+pow(c,3)) {//pow(值1,值2)值1为下标,值二为次方数
            printf("%d\n", i);
        }

    }
    return 0;
}

Guess you like

Origin blog.csdn.net/m0_62247560/article/details/125037954