下列程式碼是自動計算找零程式的一部分, 程式碼中三個主要變數分別為 Total (購買總額 ),Paid (實際支付金額 ),Change (找零金額 )。但是此程式片段有冗餘的程式碼,請找出冗餘程式碼的區塊。
1. int Total, Paid, Change;
2. …
3. Change = Paid - Total;
4. printf ("500 : %d pieces\n", (Change-Change%500)/500);
5. Change = Change % 500;
6. printf ("100 : %d coins\n", (Change-Change%100)/100);
7. Change = Change % 100;
8. // A 區
9. printf (“50 : %d coins\n”, (Change-Change%50)/50);
10. Change = Change % 50;
11. // B 區
12. printf ("10 : %d coins\n", (Change-Change%10)/10);
13. Change = Change % 10;
14. // C 區
15. printf ("5 : %d coins\n", (Change-Change%5)/5);
16. Change = Change % 5;
17. // D 區
18. printf ("1 : %d coins\n", (Change-Change%1)/1);
19. Change = Change % 1; |