基础练习——百钱买百鸡(C++)

    xiaoxiao2021-12-14  18

    公鸡5文钱一只,母鸡3文钱一只,小鸡3只一文钱, 用100文钱买一百只鸡,其中公鸡,母鸡,小鸡都必须要有,问公鸡,母鸡,小鸡要买多少只刚好凑足100文钱。

    #include<iostream> #include<math.h> using namespace std; int main() { int x,y,z; for(x=1;x<20;x++) //Rooster less than 100/5 { for(y=1;y<(100-5*x)/3;y++) { z=100-x-y; if(z%3==0 && 5*x+3*y+(100-x-y)/3==100) cout<<"Rooster:"<<x<<'\t'<<"Hen:"<<y<<'\t'<<"chicken:"<<z<<endl; } } return 0; }
    转载请注明原文地址: https://ju.6miu.com/read-969536.html

    最新回复(0)