Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
30
Task/Happy-numbers/VBScript/happy-numbers.vb
Normal file
30
Task/Happy-numbers/VBScript/happy-numbers.vb
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
count = 0
|
||||
firsteigth=""
|
||||
For i = 1 To 100
|
||||
If IsHappy(CInt(i)) Then
|
||||
firsteight = firsteight & i & ","
|
||||
count = count + 1
|
||||
End If
|
||||
If count = 8 Then
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
WScript.Echo firsteight
|
||||
|
||||
Function IsHappy(n)
|
||||
IsHappy = False
|
||||
m = 0
|
||||
Do Until m = 60
|
||||
sum = 0
|
||||
For j = 1 To Len(n)
|
||||
sum = sum + (Mid(n,j,1))^2
|
||||
Next
|
||||
If sum = 1 Then
|
||||
IsHappy = True
|
||||
Exit Do
|
||||
Else
|
||||
n = sum
|
||||
m = m + 1
|
||||
End If
|
||||
Loop
|
||||
End Function
|
||||
Loading…
Add table
Add a link
Reference in a new issue