问题描述:公鸡5元一只,母鸡3元一只,小鸡1元三只,问用100元买100只鸡,有几种方式。
#include <iostream>
using namespace std;
void func()
{
int n = 0;
for (int a = 0; a < 100; a++)
{
for (int b = 0; b < 100; b++)
{
for (int c = 0; c < 100; c++)
{
if (5 * a + 3 * b + c / 3 == 100 && a + b + c == 100)
n++;
}
}
}
cout << "有" << n << "种";
}
int main()
{
cout << "公鸡每只五元,母鸡每只3元,小鸡三只1元,问100元买100只鸡有几种买法?\n";
func();
}