第3周项目7-穷举换硬币

来源:互联网 发布:mysql数据库用户权限 编辑:程序博客网 时间:2024/06/15 06:50
01./*Copyright (c) 2016, 烟台大学计算机学院     02.*All rights reserved.     03.*文件名称:c4weeks.cpp     04.*作者:张天择    05.*完成日期:2016年 3月24日     06.*版本号:code.blocks12.11     07.*/      

问题描述:用一元人民币兑换成1分,2分,5分硬币,有多少种换法?

#include<iostream>   using namespace std;  int main()  {      int i,j,k;      for(i=0;i<=100;i++)     {          for(j=0;j<=50;j++)          {              for(k=0;k<=20;k++)             {                  if(i+j*2+k*5==100)                 {                     cout<<"1分的有"<<i<<"个";                      cout<<"2分的有"<<j<<"个";                     cout<<"5分的有"<<k<<"个";                      cout<<"\n";                  }               }         }     }     return 0;  
<img src="" alt="" style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);" />
0 0
原创粉丝点击