求帮我看看哪里错了
这是题目:张,王,李三家各有三个小孩。一天,三家的九个孩子在一起进行短跑比赛,规定不分年龄大小,第一名得9分,第二名得8分,
以此类推。比赛结果显示各家的总分相同,且这些孩子中没有同时到达终点的,也没有同一家中的两个或者三个孩子获得相连的
名次的情况。已知获得第一名的是李家的孩子,获得第二名的是王家的孩子。问获得最后一名的是谁吧家的孩子?
下面是我打的,求解惑。
int score;
main()
{
int i,j,k,who;
score=7;
score=8;
score=9;
for(i=4;i<6;i++)
for(j=4;j<7;j++)
for(k=4;1!=j&&k<7;k++)
if(k!=i&&k!=j
&&15-i-score!=15-j-score
&&15-i-score!=15-k-score
&&15-j-score!=15-j-score)
{
score=1; score=15-i-7;
score=j; score=15-j-8;
score=k; score=15-k-9;
}
for(who=0,i=1;1<=4;i++,printf("\n"))
for(j=1;j<=3;j++)
{
printf("%d",score);
if(score==1)
who=i;
}
if(who==1)
printf("The lase one arrived to end is a child form family zhang.\n");
else if(who==2)
printf("The lase one arrived to end is a child form family wang.\n");
else
printf("The lase one arrived to end is a child form family Li.\n");
} 本帖最后由 村里小黑 于 2021-10-13 18:37 编辑
提示什么错误?我看你有一些书写不规范 score=1; score=15-i-7;这一句应该是score=i;吧
村里小黑 发表于 2021-10-13 18:12
提示什么错误?我看你有一些书写不规范
D:\练习\Cpp1.cpp(20) : error C2065: 'printf' : undeclared identifier
D:\练习\Cpp1.cpp(33) : warning C4508: 'main' : function should return a value; 'void' return type assumed
这两 村里小黑 发表于 2021-10-13 18:39
score=1; score=15-i-7;这一句应该是score=i;吧
改了还是有下面两个问题 兄弟,编写代码必须严谨,尤其是 C 语言,更是敏感:
解答:
问题 1 :printf() 是输出函数,你的代码缺少头文件 #include <stdio.h>
问题 2 :main() 前面要加 int,如:int main() 本帖最后由 tianlai7266 于 2021-10-16 18:23 编辑
#include<stdio.h>
int main()
{
int score;
int i, j, k, who;
score = 7;
score = 8;
score = 9;
for (i = 4; i < 6; i++)
for (j = 4; j < 7; j++)
for (k = 4; 1 != j && k < 7; k++)
if (k != i && k != j
&& 15 - i - score != 15 - j - score
&& 15 - i - score != 15 - k - score
&& 15 - j - score != 15 - j - score)
{
score = i; score = 15 - i - 7;
score = j; score = 15 - j - 8;
score = k; score = 15 - k - 9;
}
for (who = 0, i = 1; i <= 4; i++, printf("\n"))
for (j = 1; j <= 3; j++)
{
printf("%d", score);
if (score == 1)
who = i;
}
if (who == 1)
printf("The lase one arrived to end is a child form family zhang.\n");
else if (who == 2)
printf("The lase one arrived to end is a child form family wang.\n");
else
printf("The lase one arrived to end is a child form family Li.\n");
}
书写要规范 #include<stdio.h>
#include<math.h>
int main()
{
int a, z, w, l;
a = 7;
a = 8;
a = 9;
for (z = 4; z < 6; z++)
{
for (w = 4; w < 7; w++)
{
for (l = 4; l < 7; l++)
{
if (z != w && z != l && w != l
&& 15 - a - z != 15 - a - w
&& 15 - a - z != 15 - a - l
&& 15 - a - w != 15 - a - l)
{
a = z; a = 15 - z - a;
a = w; a = 15 - w - a;
a = l; a = 15 - l - a;
}
}
}
}
for(int i = 0;i<3;i++)
{
for (int j = 0 ;j<3;j++)
{
printf("%d", a);
if (a ==1)
if (i == 0)
printf("Z");
else if (i == 1)
printf("W");
else
printf("L");
}
printf("\n");
}
return 0;
}
这是我写的
感谢各位,解决了
页:
[1]