标题:奇妙的水仙花
只看楼主
srxt06
Rank: 1
等 级:新手上路
帖 子:50
专家分:0
注 册:2007-10-7
 问题点数:0 回复次数:3 
奇妙的水仙花

和大家一起分享一个有趣的问题--水仙花
用语言解决这个问题的程序如下:
Option Explicit

Private Sub Form_Load()
Form1.AutoRedraw = True
Dim intI As Integer, strI As String
Dim intW4 As Integer, intW3 As Integer, intW2 As Integer
Dim intW1 As Integer, intAll As Single
For intI = 10 To 9999
strI = CStr(intI)
If Len(strI) = 2 Then
intW2 = Left(strI, 1)
intW1 = Right(strI, 1)
intAll = intW2 ^ 2 + intW1 ^ 2
If intAll = intI Then
Print intI
End If
End If
If Len(strI) = 3 Then
intW3 = Mid(strI, 1, 1)
intW2 = Mid(strI, 2, 1)
intW1 = Mid(strI, 3, 1)
intAll = intW3 ^ 3 + intW2 ^ 3 + intW1 ^ 3
If intAll = intI Then
Print intI
End If
End If
If Len(strI) = 4 Then
intW4 = Mid(strI, 1, 1)
intW3 = Mid(strI, 2, 1)
intW2 = Mid(strI, 3, 1)
intW1 = Mid(strI, 4, 1)
intAll = intW4 ^ 4 + intW3 ^ 4 + intW2 ^ 4 + intW1 ^ 4
If intAll = intI Then
Print intI
End If
End If
Next intI
End Sub

搜索更多相关主题的帖子: 水仙花 
2007-10-08 19:29
Sunyueliboy
Rank: 1
等 级:新手上路
帖 子:79
专家分:0
注 册:2007-9-20
得分:0 
这类题目我在<C语言编程基础>中看过,用C会有更简单的解法.
VB的还没看过,顶一下!
2007-10-08 22:30
srxt06
Rank: 1
等 级:新手上路
帖 子:50
专家分:0
注 册:2007-10-7
得分:0 
vb的特点我想大家也都很清楚:所见即所得!




努力一切皆有可能,编程亦是如此!
2007-10-08 22:40
tntzwc
Rank: 3Rank: 3
等 级:新手上路
威 望:7
帖 子:216
专家分:0
注 册:2007-4-28
得分:0 
我喜欢用C写这种程序

努力了有可能失败,不努力一定失败!
2007-10-09 09:07



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-175921-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.084886 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved