導航:首頁 > 編程語言 > 水仙花數編程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相關的資料

熱點內容
群體智能基本演算法 瀏覽:370
可編程軟體分為哪兩種 瀏覽:340
格林什麼app可以看 瀏覽:697
飛盧app仙俠熱賣推薦怎麼樣 瀏覽:722
飛秋上傳文件到共享文件夾 瀏覽:691
伺服器的共享文件夾如何訪問 瀏覽:232
復盛螺桿壓縮機講解 瀏覽:332
柱在基礎插筋需要加密嗎 瀏覽:80
51單片機中斷寄存器 瀏覽:65
壓縮文件後有病毒怎麼辦 瀏覽:618
蘋果ipad怎麼登安卓王者賬號 瀏覽:862
街頭足球伺服器已滿是什麼意思 瀏覽:462
androidspeex迴音消除 瀏覽:133
加密會議什麼意思 瀏覽:34
ubuntu命令行聯網 瀏覽:7
37選7中獎概率及演算法 瀏覽:593
加密狗哪個版本好 瀏覽:619
cisco命令手冊 瀏覽:502
omp演算法c 瀏覽:129
上海浦東機場源碼 瀏覽:885