将40元用完买这两种商品总共有多少种买法
//有2种商品,一种单价4元,一种单价2元,将40元用完买这两种商品总共有多少种买法?输出结果。
#include<iostream> //引入iostream库,才能使用输入输出流,cin和cout
using namespace std; //引入 std 命名空间
int main() //主函数,从这里开始运行代码
{
int x,y,id=0;
cout<<"有2种商品,一种单价4元,一种单价2元,将40元用完买这两种商品总共有多少种买法?输出结果。"<<endl;
cout<<endl;
for (x=1;x<=40;x++){
id++;
for (y=1;y<=40;y++){
if (x*4+2*y==40)
{
cout<<"买法"<<id<<":4元商品买"<<x<<"个,2元商品买"<<y<<"个。"<<endl;
}
}
}
}