水仙花数是指一个 n 位数 ( n>=3 ),它的每个位上的数字的 n 次幂之和等于它本身.(例如:1^3 + 5^3 + 3^3 = 153) 三位的水仙花数共有4个,分别为:153.370.371.407 代码实现: public class For_Demo2 { public static void main(String[] args) { //求水仙花数 int ge,shi,bai; int m=0; int total=0; for(int i=100;i<1000;i++){…
#include <stdio.h> int fun(int x) { int a, b, c; a = x / ; b = x % / ; c = x % ; if (x == a * a * a + b * b * b + c * c * c) ; else ; } int main() { int m; printf("1000以内的水仙花数:\n"); ; m < ; m++) { ) printf("%5d\n", m); } }…
什么是水仙花数? 水仙花数是指一个 3 位数,它的每个位上的数字的 3次幂之和等于它本身(例如:1^3 + 5^3+ 3^3 = 153). 代码1: #include<stdio.h> int main() { int m,a, b, c; m = ; printf("1000以内水仙花数为:\n"); ) { a = m / ; b = m / % ; c = m % ; if (m == a * a * a + b * b * b + c * c * c) print…
package 习题集2;//1000以内的水仙花数public class Demo02 { public static void main(String[] args) { int i = 100; while (i < 1000){ int a = i / 100 % 10; int b = i / 10 % 10; int c = i / 1 % 10; if (a * a * a + b * b * b + c * c * c == i){ System.out.println(i);…
/* 在控制台输出所有的“水仙花数” 水仙花:100-999 在以上数字范围内:这个数=个位*个位*个位+十位*十位*十位+百位*百位*百位 例如:xyz=x^3 +y^3 +z^3 怎么把三位数字拆成每位整数 思路:百位: int x= i / 100 十位: int y = i / 10 % 10 个位: int z = i % 10 */ class LoopTest3 { public static void main(String[] args) { for (int i=100; i…