(2)从键盘输入5张指定面额的纸币(以元为单位),计算并输出其总金额。面额可以为:100元、50元、10元、5元、2元、1元。

(2)从键盘输入5张指定面额的纸币(以元为单位),计算并输出其总金额。面额可以为:100元、50元、10元、5元、2元、1元。

供参考:

#include<stdio.h>
int main()
{
    int n,s=0,cnt=0;
    while(scanf("%d",&n)==1 && n!=0 && cnt < 5)//0结束输入 或 累计输入达5次
    {
        if(n==100 || n==50 || n==10 || n==5 || n==2 || n==1)
           s += n;
        cnt++;
    }
    printf("%d\n",s);
    
    return 0;
}