C语言 a[56]={41,45,44,44,26,44,42,20,20,38,37,25,45,45,45,44,20,30,39,35,38,38,28,25,30,36,20,24,32,33,41,33,51,39,20,20,44,37,38,39,42,40,37,50,50,42,43,41,42,45,42,19,39,75,17,17};任意几个数之和等于150,输出其顺序号和数字.不能

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/28 10:48:18
C语言 a[56]={41,45,44,44,26,44,42,20,20,38,37,25,45,45,45,44,20,30,39,35,38,38,28,25,30,36,20,24,32,33,41,33,51,39,20,20,44,37,38,39,42,40,37,50,50,42,43,41,42,45,42,19,39,75,17,17};任意几个数之和等于150,输出其顺序号和数字.不能
xT[OA+w$/}/MmtA 6M ުV-BzIM 1U4FV?33,O3}6&'3o9ˍwknH13υt2i(f5LI0iҠ) CB:21D )(jHVů4PU"-bR=6?G,jE56:kA6Y{ɛ%^:0oKNܹe|{ST&ggL&'gRO=gvLYvxNv@ffpVtkC3iXl07OLr_ѱ+N7ZYY} sZKJ5_g=;q/-Xu´ˊX:Q)N%5XW+݅B+RUo瞿v}0Xs/lQHl?݁IҔd/9d @;95IDz(G

C语言 a[56]={41,45,44,44,26,44,42,20,20,38,37,25,45,45,45,44,20,30,39,35,38,38,28,25,30,36,20,24,32,33,41,33,51,39,20,20,44,37,38,39,42,40,37,50,50,42,43,41,42,45,42,19,39,75,17,17};任意几个数之和等于150,输出其顺序号和数字.不能
C语言
a[56]={41,45,44,44,26,44,42,20,20,38,37,25,45,45,45,44,20,30,39,35,38,38,28,25,30,36,20,24,32,33,41,33,51,39,20,20,44,37,38,39,42,40,37,50,50,42,43,41,42,45,42,19,39,75,17,17};任意几个数之和等于150,输出其顺序号和数字.不能组成的数字同样输出其顺序号和数字.
#include "stdafx.h"
#include
#include
void main()
{
int sum=0;
int i,
a[56]={41,45,44,44,26,44,42,20,20,38,37,25,45,45,45,44,20,30,39,35,38,38,28,25,30,36,20,24,32,33,41,33,51,39,20,20,44,37,38,39,42,40,37,50,50,42,43,41,42,45,42,19,39,75,17,17};
for(i=0;i100&&sum

C语言 a[56]={41,45,44,44,26,44,42,20,20,38,37,25,45,45,45,44,20,30,39,35,38,38,28,25,30,36,20,24,32,33,41,33,51,39,20,20,44,37,38,39,42,40,37,50,50,42,43,41,42,45,42,19,39,75,17,17};任意几个数之和等于150,输出其顺序号和数字.不能
总共也就27720次测试
下面的代码,只输出了满足要求的数字(不满足的你想输出的话稍改一下)
和等于150的,不等于150的,全部输出来,那跑这段代码是为了什么啊.有27720组数据啊.
void main()
{
int a[56]={41,45,44,44,26,44,42,20,20,38,37,25,45,45,45,44,20,30,39,35,38,38,28,25,30,36,20,24,32,33,41,33,51,39,20,20,44,37,38,39,42,40,37,50,50,42,43,41,42,45,42,19,39,75,17,17};
int i, j, k;
#define N56
#define SUM150
int total = 0;
for(i = 0; i < N - 2; i ++)
for(j = i + 1; j < N -1; j++)
for(k = j + 1; k < N; k++)
{
if(a[i] + a[j] + a[k] == SUM)
{
printf("%d(%d),%d(%d),%d(%d)\r\n", a[i], i, a[j], j, a[k], k);
total++;
}
}
printf("%d\r\n", total);
}