列印1-999之內的“水仙花數”
列印1-999之內的“水仙花數”
思路分析:水仙花數就是一個三位數他的每一位上的數的立方之和等於它本身,例如153=13+53+3^3;則153是一個水仙花數;
完整程式碼:
#include<stdio.h>
#include<windows.h>
int main()
{
int i, a, b, c;
for (i = 100; i <= 999; i++)
{
a = (i / 100);//百位數字
b = (i % 100 / 10);//十位數字
c = (i % 100 % 10);//個位數字
if ((a*a*a + b*b*b + c*c*c) == i)//條件
{
printf("%d\t", i);
}
}
system("pause");
return 0;
}
執行結果:
相關推薦
列印1-999之內的“水仙花數”
列印1-999之內的“水仙花數” 思路分析:水仙花數就是一個三位數他的每一位上的數的立方之和等於它本身,例如153=13+53+3^3;則153是一個水仙花數; 完整程式碼: #include<stdio.h> #include<windows.h> in
java筆試題:找出3~999的水仙花數的三種實現方式
style col 展示 ava num get 實現 sys pack 第一種方式: package test; public class Exsercise { public static void main(String[] args) {
0-999的水仙花數
程式碼如下: #include<stdio.h>int main() { int a,b,c,i=0; int count=0; for(i=0;i<=999;i++) { a=i%10;
列印1到100的數 遇到含九的跳過
列印1到100的數 遇到含九的跳過 我先寫了這樣的 function print() { var i, j, flag = 0; for (i = 0; i < 10; i++) { for
輸入一個數字n,列印1到n位數的最大值。eg:n=3,代表列印1-999之間的數字
相關解決: package com.swordRefersToOffer; import java.util.Arrays; /** * @author 凌龍 * @date 2018/9/28 */ public class Test { public
100到999的水仙花數java實現
public class shuixianhuashu { public static void main(String[] args) { // TODO Auto-gene
用python 計算100~999的水仙花數的個數
# author : momo #計算100~999的水仙花數的個數 sum = 0 for i in range(100,1000): a = 0 temp = i while temp: a = a+(temp%10)**3 temp //
java求100到999的水仙花數(直接程式碼詳解)
/* 要求: 計算出水仙花數 三位數 100-999 個位數的立方+十位數的立方+百位數的立方 = 自己本身 153 = 1*1*1 + 5*5*5 + 3*3*3 已知三位數 123 獲取出每個數位 利用 除法,取模運算 實現步驟: 1. 定義變數
java筆記:輸出100-999的水仙花數
/************************************************************** 功能:輸出100-999的水仙花數 特別注意:水仙花數是指一個 n 位數 ( n≥3 ),它的每個位上的數字 的 n 次冪之和等於它本身。(例如:
I00012 列印三位數的水仙花數及其個數
各個位數的立方數之和等於數本身的數,稱為水仙花數。 這裡使用窮舉法列印3位數的水仙花數。 程式的關鍵是如何取出給定數的各個位的值。 另外需要注意的一點是,求和變數的初值是零。乘積變數的初值則為1。 程式如下: /* 列印三位數的水仙花數及其個數 */ #include
求出0~999之間的所有“水仙花數”並輸出。 “水仙花數”是指一個三位數,其各位數字的立方和確好等於該數本身,如;153=1+5+3?,則153是一個“水仙花數”。
程式 #include<stdio.h> #include<stdlib.h> #include<math.h> int main() { int i = 0; for(; i <= 999; i++) { int tmp = 0;
C語言 1. switch語句的使用2.輸出菱形3..求出0~999之間的所有”水仙花數“,並輸出
浮點型和零相比? #define EXP 0.000000……1 在不同作業系統下程式碼結果可能不一樣,所以定義一個精度 switch語句的使用: int main() { int day=0; scanf("%d",&day); switch(d
1.求出0~999之間的所有“水仙花數”並輸出。“水仙花數”是指一個三位數,其各位數字的立方和確好等於該數本身,如;153=1+5+3?,則153是一個“水仙花數”。
1.在螢幕上輸出以下圖案: * *** ***** ******* ********* *********** ************* *********** ********* ******* ***** *** * 2.求出0~
JS 1000以內的水仙花數 (三位數 各個數字的立方和等於本身 例如 1*1*1 + 5*5*5 + 7*7*7 = 157)
script document class AC pan code type ctype ava <!DOCTYPE html> <html> <head> <meta charset="UTF-8">
【C語言】列印水仙花數
題目:用C語言列印1000以內的水仙花數,“所謂“水仙花數”是指一個三位數,其各位數字立方和等於該數本身。 例如:153是一個“水仙花數”,因為153=1^3+5^3+3^3(1的三次方+5的三次方+3
c語言 3種方法 求出0~999之間的所有 水仙花數 並輸出
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!  
兩種方法列印水仙花數
一個三位數,它的個位的立方加上十位的立方再加上百位的立方等於這個數本身的話,此數叫作水仙花數.如:某三位數abc,如果滿足a^3+b^3+c^3=abc,則abc是水仙花數。下面我提供兩種方法列印水仙花數。 1.下面這個程式碼是比較好理解的,直接從水仙花的定義,結構a^3+b^3+c^3=abc
搜題摸魚系列(practice 3:列印水仙花數)
抄題練習/背3 。。。題從網上搜的,給自己看的,侵刪 package practice; public class three3 { public static void main(String[] args) { int i,j,k; int a,sum; for
.求出0~999之間的所有“水仙花數”並輸出。
求出0~999之間的所有“水仙花數”並輸出。 “水仙花數”是指一個三位數,其各位數字的立方和確好等於該數本身,如;153=1+5+3?,則153是一個“水仙花數”。 /* 在數論中,水仙花數(Narcissi #include <stdio.h> #include <stdli
用C語言求出0~999之間的所有“水仙花數”並輸出
執行環境: win10 vs2013 “水仙花數”是指一個三位數,其各位數字的立方和確好等於該數本身,如;153=1+5+3?,則153是一個“水仙花數”。 在數論中,水仙花數(Narcissis