什么是水仙花数? 水仙花数是指一个 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); } }
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);
水仙花数是指一个 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++){
6-11 使用函数输出水仙花数 (20 分) 水仙花数是指一个N位正整数(N≥3),它的每个位上的数字的N次幂之和等于它本身.例如:153=13+53+33. 本题要求编写两个函数,一个判断给定整数是否水仙花数,另一个按从小到大的顺序打印出给定区间(m,n)内所有的水仙花数. 函数接口定义: int narcissistic( int number ); void PrintN( int m, int n ); 函数narcissistic判断number是否为水仙花数,是则返
#-*- coding: utf-8-*-import timeimport math#获取3位数的水仙花数start1 = time.time()start = time.time() numbers = []for i in range(100,1000): a = i % 10 b = i // 10 % 10 c = i // 100 if((a ** 3) + (b ** 3) + (c ** 3)) == i: numbers.append(i) for j in numbers:
//你们的鼓励是我最大的动力 大家可以多留言评论 在接下来很长一段时间我会从初级到高级每天更新 大家有想学习的内容也可以留言哦 //现在是我做C#老师的第28天,希望和大家一起努力 加油 using System; using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks; namespace FOR{ class Program { static void