#include
#define N 8
int main() {
int a[N],b[N],c[N],d[N],i1,i2,i3,i4;float z;
a[N]=(20,34,48,66,71,80,91,104,110);
b[N]=(30,40,54,70,84,90,103,110,120);
c[N]=(33,38,52,82,95,99,110,122,135);
d[N]=(40,50,63,97,105,112,134,144,150);
for (i1 = 0;i1 <= N;i1++) {
for (i2 = 0;i2 + i1 <= N;i2++) {
for (i3 = 0;i3 + i2 + i1 <= N;i3++) {
for (i4 = 0;i4 + i3 + i2 + i1 <= N;i4++) {
z = a[i1]+b[i2]+c[i3]+d[i4];
cout<
}
}
}
return 0;
}
#include
#define N 8
main()
{
int i1,i2,i3,i4;
float z;
int a[N]={20,34,48,66,71,80,91,104,110};
int b[N]={30,40,54,70,84,90,103,110,120};
int c[N]={33,38,52,82,95,99,110,122,135};
int d[N]={40,50,63,97,105,112,134,144,150};
for(i1=0;i1
{ z=a[i1]+b[i2]+c[i3]+d[i4]; cout<
首先你定义的是只有8个数的数组啊,怎么数组里有9个数啊?
四个for循环应该可以解决吧
i1=i2=i3=i4=7;
for(;i1>=0;i1--)
{
if(i1+i2+i3+i4>N)
continue;
for(;i2>=0;i2--)
{
if(i1+i2+i3+i4>N)
continue;
for(;)
}
}
还有i3和i4自己写下吧,嗯,每个循环把数打出来就好了
for(i1=0,i2=0,i3=0,i4=0;i1
cout<
怎么选个错的答案啊?!
楼主知道a[N]=(20,34,48,66,71,80,91,104,110);的运行结果是什么吗?
这个已经不是数组赋初值了!!
首先它就数组越界,其次表达式(20,34,48,66,71,80,91,104,110);的结果是什么?
数组赋初值的写法:
int a[N]={20,34,48,66,71,80,91,104,110};
2楼正解