返回列表 發帖

硬弊換紙鈔

本帖最後由 tonyh 於 2011-12-10 17:32 編輯

讓使用者輸入想兌換的硬幣金額, 電腦回應:
能兌換成1000元鈔票幾張, 500元鈔票幾張, 100元鈔票幾張, 以及剩餘零錢多少元.
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int sum, a[4];    //a[0] a[1] a[2] a[3]
  6.     cout<<"請輸入您想兌換的硬幣: ";
  7.     cin>>sum;
  8.     cout<<"硬幣"<<sum<<"元可兌換..."<<endl;
  9.     a[0]=sum/1000;
  10.     sum=sum%1000;
  11.     a[1]=sum/500;
  12.     sum=sum%500;
  13.     a[2]=sum/100;
  14.     sum=sum%100;
  15.     a[3]=sum;
  16.     cout<<"一千元鈔票"<<a[0]<<"張, 五百元鈔票"<<a[1]<<"張, 一百元鈔票"<<a[2]
  17.         <<"張, 剩餘零錢"<<a[3]<<"元"<<endl;
  18.     system("pause");
  19.     return 0;   
  20. }
複製代碼

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int sum,a[4];
  6.     cout<<"請輸入您想換算的硬幣: ";
  7.     cin>>sum;
  8.     cout<<sum<<"硬幣可換算為..." <<endl;
  9.     a[0]=sum/1000;
  10.     sum=sum%1000;
  11.     a[1]=sum/500;
  12.     sum=sum%500;
  13.     a[2]=sum/100;
  14.     a[3]=sum%100;
  15.     cout<<a[0]<<"張一千元, "<<a[1]<<"張五百元, "<<a[2]<<"張一百元, "<<a[3]<<"元, "<<endl;
  16. system("pause");
  17. return 0;   
  18. }
複製代碼

TOP

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int sum,a[14];
  6. cout<<"請輸入你想換算的硬幣:";
  7. cin>>sum;
  8. cout<<sum<<"可換紙鈔算為..."<<endl;
  9. a[0]=sum/1000;
  10. sum=sum%1000;
  11. a[1]=sum/500;
  12. sum=sum%500;
  13. a[2]=sum/100;
  14. sum=sum%100;
  15. a[3]=sum/50;
  16. sum=sum%50;
  17. a[4]=sum/10;
  18. sum=sum%10;
  19. a[5]=sum/5;
  20. sum=sum%5;
  21. a[6]=sum/1;
  22. sum=sum%1;
  23. cout<<a[0]<<"張一千元,"<<a[1]<<"張五百元,"<<a[2]<<"張一百元,"<<a[3]<<"個五十元,"<<a[4]<<"個十元,"<<a[5]<<"個五元,"<<a[6]<<"個一元."<<endl;
  24. system("pause");
  25. return 0;
  26. }
複製代碼

TOP

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int sum,a[4];
  6.     cout<<"請輸入您想換算的硬幣: ";
  7.     cin>>sum;
  8.     cout<<sum<<"硬幣可換..." <<endl;
  9.     a[1]=sum/1000;
  10.     sum=sum%1000;
  11.     a[2]=sum/500;
  12.     sum=sum%500;
  13.     a[3]=sum/100;
  14.     a[4]=sum%100;
  15.     cout<<a[1]<<"張一千元 & "<<a[2]<<"張五百元 & "<<a[3]<<"張一百元 & "<<"剩下"<<a[4]<<"元. "<<endl;
  16.     system("pause");
  17.     return 0;   
  18. }
複製代碼

TOP

  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.   int sum, a[4];
  6.   cout<<"請輸入您想換算的硬幣:";
  7.   cin>>sum;
  8.   cout<<sum<<"硬幣可換質為..."<<endl;
  9.   a[0]=sum/1000;
  10.   sum=sum%1000;
  11.   a[1]=sum/500;
  12.   sum=sum%500;
  13.   a[2]=sum/100;
  14.   sum=sum%100;
  15.    
  16.   cout<<a[0]<<"張千元, "<<a[1]<<"張5百元, "<<a[2]<<"張1百元, "
  17.   <<"和"<<sum<<"元硬幣."<<endl;  
  18. system("pause");   
  19. return 0;
  20. }
複製代碼

TOP

本帖最後由 t3742238 於 2011-12-10 19:40 編輯
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int sum, a[8];
  6.     cout<<"請輸入您想兌換的硬幣: ";
  7.     cin>>sum;
  8.     cout<<"硬幣"<<sum<<"元可兌換..."<<endl;
  9.     a[0]=sum/2000;
  10.     sum=sum%2000;
  11.     a[1]=sum/1000;
  12.     sum=sum%1000;
  13.     a[2]=sum/200;
  14.     sum=sum%200;
  15.     a[3]=sum/100;
  16.     sum=sum%100;
  17.     a[4]=sum/50;
  18.     sum=sum%50;   
  19.     a[5]=sum/10;
  20.     sum=sum%10;  
  21.     a[6]=sum/5;
  22.     sum=sum%5;
  23.     a[7]=sum/1;
  24.     sum=sum%1;
  25.     cout<<"兩千元鈔票"<<a[0]<<"張, 一千元鈔票"<<a[1]<<"張, 兩百元鈔票"<<a[2]
  26.         <<"張, 一百元鈔票"<<a[3]<<"張"<<" 五十元硬幣"<<a[4]<<"個"
  27.         <<"十元硬幣"<<a[5]<<"個"<<" 五元硬幣"<<a[6]<<"個"
  28.         <<"一元硬幣"<<a[7]<<"個"<<endl;
  29.     system("pause");
  30.     return 0;   
  31. }
複製代碼

TOP

返回列表