第一个小应用

在鱼C看到一个寒假作业:

题目:有2元和5元RMB共63张,总计171元。请问2元和5元RMB各有多少张?

任务:写一个程序,用电脑帮弟弟做出这道题。

加一些扩展功能。

#include<math.h>
void main()
{
  int x,y,amount,money;
  printf("input number for the amount(between2,10000) of bill and the total money(between 4,50000):\n");
  scanf("%d%d",&amount,&money);
  for(x=1;x<amount;x++)
    {y=amount-x;
     if((x*2+y*5)==money)
      {
        printf("total amount=%d,totla money=%d.\nthe amount of 2 is %d and of 5 is%d.\n",amount,money,x,y);
        break;
      }
    }
  if((x==amount)&((x*2+y*5)!=money)) //若x==amount说明for循环已进行到最后一轮,此时若数目金额不一致则输入的数有误(无法匹配)
     printf("Sorry,Your input error.\n");
}
原文地址:https://www.cnblogs.com/tsembrace/p/3114371.html