看板 C_Sharp 關於我們 聯絡資訊
※ 引述《pyngtzann.bbs@micro.bio.ncue.edu.tw (好累的恩....)》之銘言: : ※ 引述《libery.bbs@ptt.cc (許我個女性友達吧:))》之銘言: : > int total = 0; : > int reverse = 1; : > for(int i = 1 ; i <= N ; i++) : > { : > total += reverse*i; : > reverse *= (-1); : > } : > print(total); : 程式少列印出1-2+3-4+5-6...........N : 但總total已經算出 int total = 0; int reverse = 1; String sequence = ""; for(int i = 1 ; i <= N ; i++) { sequence += i; total += reverse*i; reverse *= (-1); if(reverse > 0) sequence += "+"; else if(reverse < 0) sequence += "-"; else if(i == N) sequence += "="; } sequence += total; print(sequence); -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.104.237.57