已知鸡和兔的总数量n,总脚数为m。输入n和m,依次输出鸡和兔的数目。如果无解,输出“no answer”。 将下面的代码填写完整。

撰写人——软工二班——陈喜平
题目描述
已知鸡和兔的总数量n,总脚数为m。输入n和m,依次输出鸡和兔的数目。如果无解,输出“no answer”。

将下面的代码填写完整。

#include <stdio.h>
int main()
{
    int m,n,x,y;
    while (scanf("%d%d",&n,&m)!=EOF)
    {

         ………………………

          ………………………  
    }
    return 0;
}

输入
包括多组数据,每组包括2个正整数n和m。

输出
依次输出鸡和兔的数目(2个整数之间用1个空格分开)。无解时,输出“no answer”。
样例输入
14 32
10 16
15 30
20 15
5 30
样例输出
12 2
no answer
15 0
no answer
no answer
提示
来源
hnldyhy

#include <stdio.h>
int main()
{
    int m,n,x,y;
    while (scanf("%d%d",&n,&m)!=EOF)
    {
		x=(m/2)-n;
		y=n-x;
		if(x<0||y<0)
		printf("no answer\n");
		else
		printf("%d %d\n",y,x);
			
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41518597/article/details/83047782