標題:

PASCAL 7.0 寫program一問 (20點)

發問:

點先可以整出: output 係咁: Enter your amount:3682 1000-note=3 500-note=1 100-note=1 50-note=1 20-note=1 5-coin=0 2-coin=1 1-coin=0 請幫我!!20點 更新: 最好比埋點打 因為唔識打.....唔該

aa.jpg

 

此文章來自奇摩知識+如有不便請留言告知

最佳解答:

do you need to show the empty values? for example, you need to show 1 coin that is 0. but you don't show the 10 note that is also 0. why do you show 1 coin & ignore 10 note? 2008-09-18 10:59:27 補充: Please check following code. ( The code would show the value of 10 note ) program NoteCoin; uses wincrt; var N1K, N500, N100, N50, N20, N10 : integer; C5, C2, C1 : integer; val : integer; begin { Get input } write( 'Enter your amount : ' ); readln( val ); { check note/coin } { check 1000 note } N1K := 0; repeat N1K := N1K + 1; until N1K * 1000 > val; N1K := N1K - 1; val := val - ( N1K * 1000 ); { check 500 note } N500 := 0; if val >= 500 then begin N500 := 1; val := val - 500; end; { check 100 note } N100 := 0; for N100 := 1 to 5 do if ( N100 * 100 ) > val then break; N100 := N100 - 1; val := val - ( N100 * 100 ); { check 50 note } N50 := 0; if val >= 50 then begin N50 := 1; val := val - 50; end; { check 20 note } N20 := 0; for N20 := 1 to 3 do if ( N20 * 20 ) > val then break; N20 := N20 - 1; val := val - ( N20 * 20 ); { check 10 note } N10 := 0; if val >= 10 then begin N10 := 1; val := val - 10; end; { check 5 coin } C5 := 0; if val >= 5 then begin C5 := 1; val := val - 5; end; { check 2 coin } C2 := 0; for C2 := 1 to 3 do if ( C2 * 2 ) > val then break; C2 := C2 - 1; val := val - ( C2 * 2 ); { check 1 coin } C1 := 0; if val >= 1 then C1 := 1; { show output } { show 1000 note } { if N1K > 0 then } writeln( '1000 note(s) : ', N1K ); { show 500 note } { if N500 > 0 then } writeln( ' 500 note(s) : ', N500 ); { show 100 note } { if N100 > 0 then } writeln( ' 100 note(s) : ', N100 ); { show 50 note } { if N50 > 0 then } writeln( ' 50 note(s) : ', N50 ); { show 20 note } { if N20 > 0 then } writeln( ' 20 note(s) : ', N20 ); { show 10 note } { if N10 > 0 then } writeln( ' 10 note(s) : ', N10 ); { show 5 coin } { if C5 > 0 then } writeln( ' 5 coin(s) : ', C5 ); { show 2 coin } { if C2 > 0 then } writeln( ' 2 coin(s) : ', C2 ); { show 1 coin } { if C1 > 0 then } writeln( ' 1 coin(s) : ', C1 ); end. OK?

其他解答:

其實呢 你拎個total黎除1000 除完之後拎個"魚"數黎除500 如此類推 咁樣我諗會好好多|||||寫八個 variable 同八個 while loop total = 3682 thousand, five_hundred, hundred, fifty, twenty, five, two, one while (total > 1000) thousand = thousand + 1 total = total - 1000 end while while (total > 500) five_hundred = five_hundred + 1 total = total - 500 end while 最後你就會得到 3, 1, 1, 1, 1, 0, 1, 0 2008-09-19 21:11:48 補充: 成個 program 寫出黎比人交功課都有... 好彩 個 program 有野錯!!~
arrow
arrow

    rll33xb99t 發表在 痞客邦 留言(0) 人氣()