问题及代码:
/*。
*Copyright(c)2014,烟台大学计算机学院
*All right reserved,
*文件名:test.cpp
*作者:liu_feng_zi_
*完成日期:2014年10月27日
*版本号:v1.0
*
问题描述:利用穷举方法求“百鸡百钱”问题
*输入描述:
*程序输出:
*/
#include <iostream>
using namespace std;
int main()
{
int a,b,c,count=0;
for(a=0; a<=20; a++)
for(b=0; b<=33; b++)
for(c=0; c<=100; c++)
if(5*a+3*b+c/3==100&&a+b+c==100)
{
++count;
cout<<count<<":"<<"a="<<a<<" b="<<b<<" c="<<c<<endl;
}
return 0;
}
运行结果: