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

熱點內容
有個腹黑程序員男友是什麼體驗 瀏覽:110
pdf添加文本框 瀏覽:770
系統文件夾很大沒有文件 瀏覽:74
蘇寧電器app如何還分期 瀏覽:635
蘋果怎麼在主屏幕創建文件夾 瀏覽:627
河南雲伺服器租用虛擬主機 瀏覽:361
centos修改ip命令 瀏覽:779
租用伺服器屬於什麼服務類型 瀏覽:135
英雄聯盟說沒有網路連接到伺服器地址 瀏覽:28
單片機周期信號波形識別 瀏覽:42
演算法驅動的成長史 瀏覽:936
好又省APP怎麼用 瀏覽:576
pdf在線格式轉換jpg格式轉換器 瀏覽:868
中興捧月演算法大賽第二場 瀏覽:15
穿雲伺服器 瀏覽:394
單片機核心電壓表 瀏覽:151
最強大逃頂通達信指標源碼 瀏覽:441
java程序員面試寶典歐立奇 瀏覽:457
cad命令不要跟著游標 瀏覽:200
騰訊軟體伺服器是什麼 瀏覽:894