导航:首页 > 编程语言 > 水仙花数编程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相关的资料

热点内容
阿里云购买服务器如何用现金支付 浏览:683
pythontime等待 浏览:982
单片机串行通信方式 浏览:492
android表格demo 浏览:270
安卓怎么让相册不显示网页 浏览:307
php文件系统源码 浏览:720
易信java 浏览:494
北仑二级压缩螺杆机 浏览:57
加密路线免费入口 浏览:753
计算器程序员是干嘛的 浏览:363
数控编程里fo是啥键 浏览:667
javacdataxml 浏览:956
本机tcp服务器地址 浏览:439
切换pdf 浏览:104
iturns下载的app在哪里 浏览:653
云起书院App在哪里 浏览:627
怎么对hex文件进行加密 浏览:298
pdf少年时 浏览:967
两个同名文件夹同步 浏览:643
拍照文件夹哪个好用 浏览:103