嗯哼刚才课上做了一道鸡兔同笼的问题。题目如下:
鸡兔同笼,共有35个头,94条脚,求鸡和兔子各有多少只。
根据题意,列出方程:
{x+y=a
{2x+4y=b
解得x=2a-b/2,y=b/2-a.
程序如下:
#include<iostream>
#include<string>
#include<math.h>
#include<string.h>
using namespace std;
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
int a,b,x,y;
a=35;
b=94;
x=2*a-b/2;
y=b/2-a;
cout<<"x="<<x<<" y="<<y<<endl;
return 0;
}
并没有什么难度。于是我改了一下题,也算给大家出题了:
鸡兔同笼,共有h个头,f条脚,求鸡和兔子各有多少只。
还是列出刚才那个方程。答案还是那个。但程序就需要改一下~:
#include<iostream><