#include<stdio.h> intmain(){ int i, a, b, c; for (i = 100; i <= 999; i++) { a = i % 10; b = i / 10 % 10; c = i / 100 % 10; if (i == a * a * a + b * b * b + c * c * c) { printf("%d ", i); } } return0; }
2.判断素数
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include<stdio.h> intmain(){ int i, num; printf("please input the number :"); scanf("%d", &num); for (i = 2; i < num; i++) { if (num % i == 0) { printf("%d 不是素数\n", num); return0; } } printf("%d 不是素数\n", num); return0; }
3.判断完数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include<stdio.h> int main() { int i, num, sum; printf("please input the number :"); scanf("%d", &num); sum = 0; for (i = 1; i < num; i++) { if (num% i == 0) sum = sum + i; } if (num == sum) { printf("%d 是完数\n", num); } else { printf("%d 不是完数\n", num); } return0; }