三位數,如果它的各位數字之立方和等於該數本身,則稱為水仙

時間 2021-10-16 13:01:26

1樓:家在豫北

你是想要程式還是什麼??

用vb編寫:找出所有的「水仙花數」。 「水仙花數」是指一個三位數,其各位數字的立方和等於該數本身

2樓:大野瘦子

**為:

using system;

using system.collections.generic;

using system.text;

namespace _

class program

static void main(string args)

console.writeline("一重迴圈判斷:");

console.writeline("水仙花數有:");

int i,j, k, l;

for (i = 100; i < 1000;i++)

j = i / 100;

k = i %100/10;

l = i % 10;

int n = j * j * j + k * k * k + l * l * l;

if (n == i)

console.writeline(n);

console.writeline("三重迴圈判斷:");

console.writeline("水仙花數有:");

int q, w, e, r;

for(q=1;q<=9;q++)

for(w=0;w<=9;w++)

for (e = 0; e <= 9; e++)

int s = q * 100 + w * 10 + e;

int t = q * q * q + w * w * w + e * e * e;

if (s == t)

console.writeline(s);

注意事項

自定義函式is(number)判斷number的各位數字立方和是否等於它本身,如is(121)返回值0,is(153)返回值1。 主函式輸入兩個正整數m和n(m>=1, n<=1000),輸出m-n之間的所有滿足各位數字和等於它本身的數。

input

多組測試資料,每組輸入兩個正整數m和n(m>=1, n<=1000)。

output

輸出m-n之間的所有滿足各位數字立方和等於它本身的數,空格隔開(最後一個數後無空格)。

sample input

1 100

50 200

50 500

sample output

153 370 371 407

#include

#include

int is(int number)

int s,sum=0;

while(number!=0)

s=number%10;//不斷取餘,直至為0

sum+=pow(s,3);

number=number//10;不斷去尾,直至為0

return sum;

int main(void)

int m,n,k,flag;

flag=1;

for(k=m;k<=n;k++)

if(k==is(k))

if(flag!=0)

printf("%d",k);

flag=0;

else

printf(" %d",k);

printf("\n");

return 0;

3樓:livingroom寶貝

private sub command1_click()dim a%, b%, c as integerfor a = 1 to 9

b = 0

do while b <= 9

c = 0

do until c > 9

if a ^ 3 + b ^ 3 + c ^ 3 = 100 * a + 10 * b + c then

print "水仙花數"; 100 * a + 10 * b + cend if

c = c + 1

loop

b = b + 1

loop

next a

end sub

我的文庫有好多呢。

我的輸出與題目有些出入。

4樓:匿名使用者

private sub form_click()dim i, j, m, n as integerfor n = 100 to 999

i = n \ 100

j = (n mod 100) \ 10

m = n mod 10

if i ^ 3 + j ^ 3 + m ^ 3 = n thenprint n; "="; i; "^3+"; j; "^3+"; m; "^3"

end if

next n

end sub

5樓:

private sub form_load()show

print vbcrlf;

print vbcrlf;

dim a as integer, b, cfor i = 100 to 999

a = i \ 100

b = (i mod 100) \ 10

c = i mod 10

if (a ^ 3 + b ^ 3 + c ^ 3 = i) then

print tab(10); i & "=" & a & "^3+" & b & "^3+" & c & "^3"

end if

next i

end sub

兩個三位數相加,和是幾位數,兩個三位數相加,它們的和可能是幾位數 謝謝!

可能是三位數,也可能是四位數 可能四位數,可能三位數 鈽炶壊鐢封槣 三位 最多是四位 兩個三位數相加,它們的和可能是幾位數?謝謝! 蒲蒲的小窩 可能是 4位數 或是 3位數 舉個例子 100 100 200 999 999 1998 數學賈老師 100 101 201 三位數 900 901 180...

用7 1 數字組成最大三位數和最小三位數,無論如何計算,結果等於

871 178 693 601 106 495 611 116 495 621 126 495 671 176 495 681 186 495 691 196 495 702 207 495 712 217 495 782 287 495 792 297 495 803 308 495 873 37...

三位數乘一位數怎樣列豎式計算,三位數乘三位數的列豎式怎麼列

墨汁諾 例如 234 7 1638 主要對齊位數,然後計算準確即可,在計算時,積與因數的個位數與個位數要上下對齊 十位數與十位數上下對齊,也就是說相同數位要上下對齊。一個數的第i位乘上另一個數的第j位,就應加在積的第i j 1位上。除法如42除以7。從4開始除 從高位到低位 除法用豎式計算時,從最高...