#include<iostream> const int SIZE = 9; int coin[SIZE] = {10000, 5000, 2000, 1000, 500, 100, 50, 20, 10}; int num[SIZE]; int exchange(int n); int main() { using namespace std; double money; string name[SIZE] = {"一百元", "五十元", "二十元", "十元", "5元", "1元", "5角", "2角", "1角"}; cout << "请输入金额:"; cin >> money; int n = (int)(money*100); exchange(n); for(int i=0; i<SIZE; i++) { cout << name[i] << "币种: " << num[i] << " 张\n"; } return 0; } int exchange(int n) { int i; for (i=0; i<SIZE; i++) if (n >= coin[i]) break; while (n>0 && i<SIZE) { if(n >= coin[i]) { n -= coin[i]; num[i]++; }else if(n<10 && n>=5) { num[SIZE-1]++; break; }else i++; } return 0; }
原文地址:http://blog.csdn.net/guugle2010/article/details/41117227