當前位置:首頁 » 花店知識 » 循環水鮮花數

循環水鮮花數

發布時間: 2021-12-26 00:09:09

Ⅰ java中for循環題:列印出所有的"水仙花數",所謂"水仙花數"是指一個三位數,其各位數字立方和等於該數本身

//水仙花的個數
public class LianXi3 {
public static void main(String args[]){
int a,b,c,count=0;
for(a=1;a<=9;a++){//a不能等於0
for(b=0;b<=9;b++){
for(c=0;c<=9;c++){
if((a*a*a+b*b*b+c*c*c)==(a*100+b*10+c)){
count++;
System.out.println("第"+count+"個水仙花數是:"+(a*100+b*10+c));
}
}
}
}
}
}

不知道能看明白不。。。

Ⅱ 水仙花數 java for循環的問題!

publicclassShuiXian
{

publicstaticvoidmain(String[]args)

{

//x用來臨時保存百位十位和個位

intx=0,y=0,temp=0;





for(inti=100;i<150;i++)

{

//System.out.println("i:"+i);

//temp=i;

x=i/100;//取出百位3345

y=x*x*x;//用y計數,得到了百位數的立方和。

//System.out.println("y_1:"+y);

i-=x*100;//得到2位數45



x=i/10;//取得十位上的數字4

y+=x*x*x;//把第二位數的立方和加上y=9+64

//System.out.println("y_2:"+y);


i-=x*10;//得到個位上的數

y+=i*i*i;

//System.out.println("y_3:"+y);


if(i==y)

{

System.out.println("temp:"+temp);

}


}


}
}

Ⅲ (循環)求水仙花數。所謂水仙花數,是指一個三位數abc,

水仙花數(Narcissistic number)也被稱為超完全數字不變數(pluperfect digital invariant, PPDI)、自戀數、自冪數、阿姆斯壯數或阿姆斯特朗數(Armstrong number),水仙花數是指一個 n 位數(n≥3 ),它的每個位上的數字的 n 次冪之和等於它本身(例如:1^3 + 5^3+ 3^3 = 135)。
pascal代碼:

var a, b, c, i, t : integer;
begin
i := 100;
repeat
a:=trunc(i/100);
b:=trunc(i/10) - a*10;
c:=i-trunc(i/10) * 10;
t:= a*a*a + b*b*b + c*c*c;
if i = t then
writeln(i,'=',a,'^3+',b,'^3+',c,'^3');
i := i + 1 until i > 999
end.

Ⅳ C語言三重循環輸出所有的「水仙花數」

忘了一對花括弧啊,滿足if條件後不能只給i賦值呀,下邊那句printf也得一並執行啊,所以這2句得加一對花括弧,表示語句塊,完整代碼如下:
#include<stdio.h>
main()
{
int
a,b,c,i;
for(a=1;a<=9;a++)
for(b=0;b<=9;b++)
for(c=0;c<=9;c++)
if(a*100+b*10+c==a*a*a+b*b*b+c*c*c)
{i=a*100+b*10+c;
printf("%d\n",i);}
}

Ⅳ 用循環語句求所有的水仙花數(for--next)

看來我來的不晚
VB實現的,你用著看吧,源碼如下
Sub Main()
Dim a As Integer, b As Integer, c As Integer, i As Integer

For i = 100 To 999
a = i Mod 10
b = (i - a) / 10 Mod 10
c = (i - b * 10) / 100

If a * a * a + b * b * b + c * c * c = i Then
Console.WriteLine(i)
End If
Next
End Sub

Ⅵ while 循環求所有水仙花數

while(x<1000)
{
a=x%10;
b=(x%100-a)/10;
c=(x-x%100)/100;
if(a*a*a+b*b*b+c*c*==x)

System.out.println(x); x++;

}

Ⅶ 在計算機中for循環語句,怎麼求水仙花數

#include <stdio.h>

int main(void)
{
int i,j,k;

for (i=1;i<=9;i++)
{
for (j=0;j<=9;j++)
{
for (k=0;k<=9;k++)
{
if (100*i + 10*j + k == i*i*i +j*j*j + k*k*k)
{
printf("%d%d%d\n",i,j,k);
}

}
}
}
return 0;
}

Ⅷ matlab中用while循環數水仙花數

%一個三位整數各位數字的立方和等於該數本身則稱該數為水仙花數。
n=0;
m=100;
while (m<1000)
m1=fix(m/100);
m2=rem(fix(m/10),10);
m3=rem(m,10);
if m==m1*m1*m1+m2*m2*m2+m3*m3*m3;
n=n+1;
disp(['第',num2str(n),'個水仙花數是:',num2str(m)]);
end,
m=m+1;
end,
第1個水仙花數是:153
第2個水仙花數是:370
第3個水仙花數是:371
第4個水仙花數是:407
邁特萊博

Ⅸ while循環水仙花數python代碼

n = 100

t = ''
while n < 1000:
a = int(str(n)[0]) #先變成字元串提取百位,再變成整數用於計算
b = int(str(n)[1])
c = int(str(n)[2])
if a**3+b**3+c**3 ==n:
t +=(f'{n},') # t = t + n+',' 這里的,用於題目要求的逗號的分割
n +=1 #每次循環讓數字進行+1,直到1000
print(t[:-1]) #不對最後有一位『,』進行輸出

輸出結果是153,370,371,407

Ⅹ c語言求水仙花數最基礎的for循環用法

#include<stdio.h>
intmain(void){
inta,b,c;
for(a=1;a<10;a++)
for(b=0;b<10;b++)
for(c=0;c<10;c++)
if(a*100+b*10+c==a*a*a+b*b*b+c*c*c)
printf("%d ",a*100+b*10+c);
return0;
}

熱點內容
玫瑰公寓酒店 發布:2025-08-04 15:20:07 瀏覽:903
梅花的鉛筆畫怎麼畫 發布:2025-08-04 15:19:03 瀏覽:920
2015青州花卉 發布:2025-08-04 15:16:50 瀏覽:353
香彩雀花語 發布:2025-08-04 14:54:12 瀏覽:196
節慶插花圖片 發布:2025-08-04 14:52:59 瀏覽:699
金櫻花的功效 發布:2025-08-04 14:46:52 瀏覽:462
黑白裝飾花卉 發布:2025-08-04 14:46:04 瀏覽:902
七夕已復制 發布:2025-08-04 14:41:21 瀏覽:923
棉岩盆栽 發布:2025-08-04 14:39:57 瀏覽:633
公司植樹節栽種綠植活動文案 發布:2025-08-04 14:39:49 瀏覽:60