導航:首頁 > 編程語言 > 水仙花數編程vb

水仙花數編程vb

發布時間:2024-11-09 14:22:21

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

代碼為:

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);

}

}

}

}

(1)水仙花數編程vb擴展閱讀:

注意事項

自定義函數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

1

153

153 370 371 407

#include<stdio.h>

#include<math.h>

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;

while(scanf("%d%d",&m,&n)!=EOF)

{

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(" ");

}

return 0;

}

閱讀全文

與水仙花數編程vb相關的資料

熱點內容
程序員年會打籃球 瀏覽:487
app的意見怎麼寫 瀏覽:294
企業app營銷應該如何做 瀏覽:583
app資源庫里圖標怎麼移動 瀏覽:539
雲優采安卓如何下載 瀏覽:655
主升黃金線源碼 瀏覽:518
如何在第二個手機上登錄理想app 瀏覽:945
個人主頁靜態網頁源碼 瀏覽:476
蘋果相冊文件夾怎麼恢復 瀏覽:859
中國雲通訊伺服器 瀏覽:457
小白學python看什麼書 瀏覽:957
只讀文件夾可以上傳文件 瀏覽:732
python不列印換行符 瀏覽:160
程序員那麼可愛公司吻戲 瀏覽:676
伺服器硬碟背板有什麼作用 瀏覽:556
壓縮機裝什麼網 瀏覽:677
單片機如何實現奇偶校驗 瀏覽:696
如何下載廣西防貧app 瀏覽:57
熊團子的解壓視頻 瀏覽:556
程序員坐太久腸胃不好 瀏覽:95