一、 作业要求
作业由两部分构成:源程序文件+程序设计说明文档,要求独立完成,雷同代码不得分,大作业题库见群文件。
程序功能要求(评分点):
1, 程序功能不限(能编译运行10分)
2, 必须包含顺序结构、选择分支结构、循环结构(20分)
3, 必须包含数组(20分)
4, 必须包含一个以上的函数(20分)
5, 可以包含指针(20分)
6, 可以包含结构体(10分)
编程序求 5X+2Y+Z=50 的所有非负整数解。
上面那个图是没用的。
求一个完整能运行的代码
你看我这个能不能拿100分?
#include <stdio.h>
typedef struct
{
unsigned int X;
unsigned int Y;
unsigned int Z;
} Solution;
unsigned int GetSolutionCount()
{
unsigned int count = 0;
for (int i = 0; i <= 10; i++)
{
for (int j = 0; j <= 25; j++)
{
for (int k = 0; k <= 50; k++)
{
if (5 * i + 2 * j + k == 50)
{
count++;
}
}
}
}
return count;
}
void PrintAllSolutions(Solution* solutions, unsigned int count)
{
unsigned int printCount = 0;
for (int i = 0; i < count; i++)
{
printf("{ ");
printf("%2u,", (solutions + i)->X);
printf("%2u,", (solutions + i)->Y);
printf("%2u", (solutions + i)->Z);
printf(" }\t");
printCount++;
if (printCount % 5 == 0)
{
printf("\n");
}
}
}
/* 求 5X+2Y+Z=50 的所有非负整数解 */
int main()
{
unsigned int count = GetSolutionCount();
Solution solutions[count];
unsigned int index = 0;
for (int i = 0; i <= 10; i++)
{
for (int j = 0; j <= 25; j++)
{
for (int k = 0; k <= 50; k++)
{
if (5 * i + 2 * j + k == 50)
{
solutions[index].X = i;
solutions[index].Y = j;
solutions[index].Z = k;
index++;
}
}
}
}
PrintAllSolutions(solutions, count);
return 0;
}