从1-33中选6个数字,其数字不同,和值等于86结果N个组合。有什么公式可以解决,如电子表格等

2024-12-05 07:47:47
推荐回答(3个)
回答1:

在Excel里,同时按Alt和F11进入宏界面,点菜单的插入,模块,粘贴如下代码:
Sub test()
Application.ScreenUpdating = False
Dim i, j, k, l, m, n, x As Integer
x = 1
For i = 1 To 28
For j = i + 1 To 29
For k = j + 1 To 30
For l = k + 1 To 31
For m = l + 1 To 32
For n = m + 1 To 33
If i + j + k + l + m + n = 86 Then
Cells(x, 1) = i & "," & j & "," & k & "," & l & "," & m & "," & n
x = x + 1
'If x Mod 500 = 1 Then
'If MsgBox("Continual?", vbYesNo, "Hi") = vbNo Then Exit Sub
'End If
End If
Next
Next
Next
Next
Next
Next
Application.ScreenUpdating = True
End Sub

在此界面直接按F5运行此宏,等一会,完成。

回答2:

这可以用C语言解决源代码如下:#include
#define uchar unsigned char
#define uint unsigned int
void main()
{
uchar Data_1,Data_2,Data_3,Data_4,Data_5,Data_6;
uint Count=0;
char char_1;
for(Data_1=0;Data_1<=33;Data_1++)
for(Data_2=0;Data_2<=33;Data_2++)
for(Data_3=0;Data_3<=33;Data_3++)
for(Data_4=0;Data_4<=33;Data_4++)
for(Data_5=0;Data_5<=33;Data_5++)
for(Data_6=0;Data_6<=33;Data_6++)
{
if(Data_1+Data_2+Data_3+Data_4+Data_5+Data_6==86)
{
printf("Data_1=%d,Data_2=%d,Data_3=%d,Data_4=%d,Data_5=%d,Data_6=%d\n",Data_1,Data_2,Data_3,Data_4,Data_5,Data_6);
Count++;
if(Count%20==0)
{
Flag:
printf("Please input c or e");
scanf("%c",&char_1);
if(char_1=='c')
continue;
else if(char_1=='e')
return;
else
goto Flag;
}
} }
}该代码采用TURBO C编译通过,由于该题要求所产生的数字组合太多,所以代码中每显示20组数字组合就会询问一次,如需继续显示则输入C,则会显示下20组数字组合,如需结束则输入E,则会退出程序。截图如下:

回答3:

貌似可以用C语言编个小程序来求