#include <iostream>
using namespace std;
int main()
{
int tou,jiao,tu,ji,i;
cout<<"欢迎使用“鸡兔同笼”题型(方程)作弊器\n";
cout<<"请输入头数:";
cin>>tou;
cout<<"请输入脚数:";
cin>>jiao;
if(tou<=0||jiao<=0)
{
for(int n=0;1;n++)
{
cout<<"\n输入错误,请重新输入!\n"<<endl;
cout<<"请输入头数:";
cin>>tou;
cout<<"请输入脚数:";
cin>>jiao;
break;
}
}
cout<<"\答案:\n";
cout<<"解:设兔有x只,则鸡有("<<tou<<"-x)只。\n";
cout<<"4x+2("<<tou<<"-x)="<<jiao<<endl;
i=2*tou;
cout<<" 4x+"<<i<<"-2x="<<jiao<<endl;
cout<<" 4x-2x+"<<i<<"="<<jiao<<endl;
cout<<" 2x+"<<i<<"="<<jiao<<endl;
cout<<" x+"<<i<<"-"<<i<<"="<<jiao<<"-"<<i<<endl;
i=jiao-i;
cout<<" 2x"<<"="<<i<<endl;
cout<<" 2x/2"<<"="<<i<<"/2"<<endl;
i=i/2;
cout<<" x"<<"="<<i<<endl;
ji=tou-i;
tu=i;
cout<<"鸡"<<tou<<"-"<<tu<<"="<<ji<<"(只)"<<endl;
cout<<"答:鸡有"<<ji<<"只,"<<"兔有"<<tu<<"只。" ;
return 0;
}
评论0