发工资
统计一元二元五元十元五十元一百元出现的总个数
丫的我条件表达式用的不熟悉
#include <stdio.h> int main(void) { int n,i,m; while(scanf("%d",&n) && n) { int yibai , wushi , shi , wu , er , yi , sum = 0; for(i = 0;i < n ;i++) { yibai = wushi = shi = wu = er = yi = 0; scanf("%d",&m); yibai = m / 100; wushi = m % 100 / 50; shi = m % 50 / 10; wu = m % 10 / 5; er = m % 5 / 2; yi = m % 2; sum += yibai+wushi+shi+wu+er+yi; } printf("%d ",sum); } return 0; }
参考答案
#include <stdio.h> int main(void) { int n, i, x, sum; while (scanf("%d", &n), n) { sum = 0; for (i = 0 ; i < n ; i++) { scanf("%d", &x); sum += x / 100; x %= 100; sum += x / 50; x %= 50; sum += x / 10; x %= 10; sum += x / 5; x %= 5; sum += x / 2; x %= 2; sum += x; } printf("%d ", sum); } return 0; }