c语言程序设计 题目一道,求解
现在有12只外表、颜色、大小均相同的小球,这12只球中有一个是坏球,但不知这个坏球是中还是轻,给出一天平,要求进行三次称重称出坏球,并知道其实轻还是重。编程实现上述过程。...
现在有12只外表、颜色、大小均相同的小球,这12只球中有一个是坏球,但不知这个坏球是中还是轻,给出一天平,要求进行三次称重称出坏球,并知道其实轻还是重。
编程实现上述过程。
我要程序啊。。c语言的,谢谢,只要程序即可
nousername@qq.com,贴出来也行,发我邮箱也行
注意:如果只是数学解题,100%不采纳,必须有程序,关键是C语言程序源码,谢谢!!!!!!! 展开
编程实现上述过程。
我要程序啊。。c语言的,谢谢,只要程序即可
nousername@qq.com,贴出来也行,发我邮箱也行
注意:如果只是数学解题,100%不采纳,必须有程序,关键是C语言程序源码,谢谢!!!!!!! 展开
6个回答
展开全部
#include<stdio.h>
int x,y,z,num,i,a[13]={0,0,0,0,0,0,0,0,0,0,0,0,0};
void main()
{
printf("The number of the ball:");
scanf("%d",&num);
printf("light is -1,heavy is 1:");
scanf("%d",&i);
a[num]=i;
while((num<=12)&&(num>=1))
{
x=a[1]+a[2]+a[3]+a[4];
y=a[5]+a[6]+a[7]+a[8];
z=a[9]+a[10]+a[11]+a[12];
if(x==y)
{
x=a[9]+a[10]+a[11];
y=a[1]+a[2]+a[3];
if(x==y)
{
if(a[12]>a[1])
printf("The number of 12 ball is heavy\n");
else
printf("The number of 12 ball is light\n");
}
if(x>y)
{
if(a[9]==a[10])
printf("The number of 11 ball is heavy\n");
if(a[9]>a[10])
printf("The number of 9 ball is heavy\n");
if(a[9]<a[10])
printf("The number of 10 ball is heavy\n");
}
if(x<y)
{
if(a[9]==a[10])
printf("The number of 11 ball is light\n");
if(a[9]>a[10])
printf("The number of 10 ball is light\n");
if(a[9]<a[10])
printf("The number of 9 ball is light\n");
}
}
if(x>y)
{
x=a[4]+a[5]+a[6];
y=a[7]+a[8]+a[9];
if(x==y)
{
if(a[1]==a[2])
printf("The number of 3 ball is heavy\n");
if(a[1]>a[2])
printf("The number of 1 ball is heavy\n");
if(a[1]<a[2])
printf("The number of 2 ball is heavy\n");
}
if(x>y)
{
if(a[7]==a[8])
printf("The number of 4 ball is heavy\n");
if(a[7]<a[8])
printf("The number of 7 ball is light\n");
if(a[7]>a[8])
printf("The number of 8 ball is light\n");
}
if(x<y)
{
if(a[5]<a[6])
printf("The number of 5 ball is light\n");
if(a[5]>a[6])
printf("The number of 6 ball is light\n");
}
}
if(x<y)
{
x=a[4]+a[5]+a[6];
y=a[7]+a[8]+a[9];
if(x==y)
{
if(a[1]==a[2])
printf("The number of 3 ball is light\n");
if(a[1]>a[2])
printf("The number of 2 ball is light\n");
if(a[1]<a[2])
printf("The number of 1 ball is light\n");
}
if(x<y)
{
if(a[7]==a[8])
printf("The number of 4 ball is light\n");
if(a[7]>a[8])
printf("The number of 7 ball is heavy\n");
if(a[7]<a[8])
printf("The number of 8 ball is heavy\n");
}
if(x>y)
if(a[5]<a[6])
printf("The number of 6 ball is heavy\n");
if(a[5]>a[6])
printf("The number of 5 ball is heavy\n");
}
printf("The number of the ball:");
scanf("%d",&num);
printf("light is -1,heavy is 1:");
scanf("%d",&i);
a[num]=i;
}
}
int x,y,z,num,i,a[13]={0,0,0,0,0,0,0,0,0,0,0,0,0};
void main()
{
printf("The number of the ball:");
scanf("%d",&num);
printf("light is -1,heavy is 1:");
scanf("%d",&i);
a[num]=i;
while((num<=12)&&(num>=1))
{
x=a[1]+a[2]+a[3]+a[4];
y=a[5]+a[6]+a[7]+a[8];
z=a[9]+a[10]+a[11]+a[12];
if(x==y)
{
x=a[9]+a[10]+a[11];
y=a[1]+a[2]+a[3];
if(x==y)
{
if(a[12]>a[1])
printf("The number of 12 ball is heavy\n");
else
printf("The number of 12 ball is light\n");
}
if(x>y)
{
if(a[9]==a[10])
printf("The number of 11 ball is heavy\n");
if(a[9]>a[10])
printf("The number of 9 ball is heavy\n");
if(a[9]<a[10])
printf("The number of 10 ball is heavy\n");
}
if(x<y)
{
if(a[9]==a[10])
printf("The number of 11 ball is light\n");
if(a[9]>a[10])
printf("The number of 10 ball is light\n");
if(a[9]<a[10])
printf("The number of 9 ball is light\n");
}
}
if(x>y)
{
x=a[4]+a[5]+a[6];
y=a[7]+a[8]+a[9];
if(x==y)
{
if(a[1]==a[2])
printf("The number of 3 ball is heavy\n");
if(a[1]>a[2])
printf("The number of 1 ball is heavy\n");
if(a[1]<a[2])
printf("The number of 2 ball is heavy\n");
}
if(x>y)
{
if(a[7]==a[8])
printf("The number of 4 ball is heavy\n");
if(a[7]<a[8])
printf("The number of 7 ball is light\n");
if(a[7]>a[8])
printf("The number of 8 ball is light\n");
}
if(x<y)
{
if(a[5]<a[6])
printf("The number of 5 ball is light\n");
if(a[5]>a[6])
printf("The number of 6 ball is light\n");
}
}
if(x<y)
{
x=a[4]+a[5]+a[6];
y=a[7]+a[8]+a[9];
if(x==y)
{
if(a[1]==a[2])
printf("The number of 3 ball is light\n");
if(a[1]>a[2])
printf("The number of 2 ball is light\n");
if(a[1]<a[2])
printf("The number of 1 ball is light\n");
}
if(x<y)
{
if(a[7]==a[8])
printf("The number of 4 ball is light\n");
if(a[7]>a[8])
printf("The number of 7 ball is heavy\n");
if(a[7]<a[8])
printf("The number of 8 ball is heavy\n");
}
if(x>y)
if(a[5]<a[6])
printf("The number of 6 ball is heavy\n");
if(a[5]>a[6])
printf("The number of 5 ball is heavy\n");
}
printf("The number of the ball:");
scanf("%d",&num);
printf("light is -1,heavy is 1:");
scanf("%d",&i);
a[num]=i;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询