English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

1~38的正整數中,任意五個正整數相加,值介於81~100間的有幾種組合?
請寫出作法

2007-01-09 18:47:03 · 1 個解答 · 發問者 下一位 1 in 電腦與網際網路 程式設計

1 個解答

Public Sub Add5N()
Dim i, j, k, m, n, s As Integer
Dim c As Single
c = 0
For i = 1 To 34
For j = i + 1 To 35
For k = j + 1 To 36
For m = k + 1 To 37
For n = m + 1 To 38
s = i + j + k + m + n
If (81 < s And s < 100) Then
c = c + 1
Print i & " + " & j & " + " & k & " + " & m & " + " & n & " = " & s
End If
Next n
Next m
Next k
Next j
Next i
MsgBox "Total : " & c ' 有 141921 種喔
End Sub
如果有問題, 請來函討論. 不然, 我可能會錯失你再補充的疑點.

2007-01-10 11:14:26 補充:
抱歉用錯語言了
#include

void main()
{
int i,j,k,m,n,s;
long c;

2007-01-10 11:16:17 補充:
c=0;
for (i=1; i<35; i )
for (j=i 1; j<36; j )
for (k=j 1; k<37; k )
for (m=k 1; m<38; m )
for (n=m 1; n<39; n )
{
s=i j k m n;
if(81 {
c ;
if (c % 1000 == 0)
printf("%d %d %d %d %d = %d\n",i,j,k,m,n,s);
}
}
printf("Total : %ld \n", c);
}

2007-01-10 05:54:15 · answer #1 · answered by JJ 7 · 0 0

fedest.com, questions and answers