什么是水仙花数? 水仙花数是指一个 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
#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); } }
水仙花数是指一个 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++){
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);
num = 100 while num <= 999: a = num % 10 #取个位数 b = num // 10 % 10 #取十位数 c = num // 100 #取百位数 if num == a**3 + b**3 + c**3: print (num) num += 1 #python不支持 num++ 之类的写法
//你们的鼓励是我最大的动力 大家可以多留言评论 在接下来很长一段时间我会从初级到高级每天更新 大家有想学习的内容也可以留言哦 //现在是我做C#老师的第28天,希望和大家一起努力 加油 using System; using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks; namespace FOR{ class Program { static void
package printDaffodilNumber; /* * 题目:打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身.(100~1000) * 比如:153是一个"水仙花数",因为153=1的三次方+5的三次方+3的三次方. */ public class printNumber { static int number1; static int number2; static int number3;
题目: 请判断一个数是不是水仙花数.其中水仙花数定义各个位数立方和等于它本身的三位数.输入有多组测试数据,每组测试数据以包含一个整数n(100<=n<1000)输入0表示程序输入结束.输出如果n是水仙花数就输出Yes否则输出No样例输入1531540样例输出YesNo class Shui: def __init__(self,str): self.str=str def carculate(self): n=len(self.str) sum = 0 for i in range(0,n):
水仙花数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 91418 Accepted Submission(s): 27061 Problem Description 春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,他是这样定义的:“水仙花数”是指一个三位数,它的各位数字的立方和等于其本身,比如:153=1^3+