永发信息网

C++语言编写程序,用一百元买一百只鸡,公鸡一只5元,母鸡一只3元,小鸡一元三只。求出公鸡母鸡小鸡

答案:2  悬赏:60  手机版
解决时间 2021-04-02 13:41
  • 提问者网友:抽煙菂渘情少年
  • 2021-04-02 00:23
C++语言编写程序,用一百元买一百只鸡,公鸡一只5元,母鸡一只3元,小鸡一元三只。求出公鸡母鸡小鸡
最佳答案
  • 五星知识达人网友:行雁书
  • 2021-04-02 01:31
#include
void main()
{
int cock,hen,chick;
cout<<"公鸡\t"<<"母鸡\t"<<"小鸡\n";
for(cock=0;cock<=20;cock++) //100元最多能买20只公鸡
for(hen=0;hen<33;hen++) //100元最多能买33只母鸡
{
chick=(100-5*cock-3*hen)*3;
if(cock+hen+chick==100)
cout< }
}
全部回答
  • 1楼网友:独行浪子会拥风
  • 2021-04-02 02:20
int Inchild , Inman(1) , Inwomen , count , money , n;
cout << "please input renshu" << endl ;
cin >> count >> money;
while(money < ( count + 3) )
{
cout << "wrong please try again" << endl ;
cin >> count >> money;
}
if ((money - count)%2 == 0)
{
n = (money - count - 1)/2 ;
}
else n = (money - count)/2 ;
for ( int Inman = 1 ; Inman <= n ; Inman++)
{
Inwomen = money - count - 2 * Inman ;
Inchild = count - Inman - Inwomen ;
if ( 3 * Inman + 2 * Inwomen + Inchild == money)
{
cout << Inman << " resaul :" << "mam :" << Inman << " women :" << Inwomen << " child :" << Inchild << endl ;
}
}
把inman inwomen inchild 换成公鸡 母鸡 小鸡就可以了
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯