View Code
// // main.m // Money // //从键盘输入一个指定金额(以元为单位,如345.78),然后显示支付该金额的各种面额人民币数量,要求显示100元、50元、10元、5元、2元、1元、5角、1角、5分、1分各多少张 // // Created by han jun on 13-2-15. // Copyright (c) 2013年 han jun. All rights reserved. // #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { double money = 0.0; printf("请输入您的钱:"); scanf("%lf", &money); printf("您的钱是:%lf\n", money); int i1=0,i2=0,i3=0,i4=0,i5=0,i6=0,i7=0,i8=0,i9=0,i10=0; while (money > 100.0) { i1++; money -= 100.0; } while (money > 50.0) { i2++; money -= 50.0; } while (money > 10.0) { i3++; money -= 10.0; } while (money > 5.0) { i4++; money -= 5.0; } while (money > 2.0) { i5++; money -= 2.0; } while (money > 1.0) { i6++; money -= 1.0; } while (money > .5) { i7++; money -= .5; } while (money > .1) { i8++; money -= .1; } while (money > .05) { i9++; money -= .05; } while (money > .01) { i10++; money -= .01; } printf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n", i1,i2,i3,i4,i5,i6,i7,i8,i9,i10); } return 0; }