作者libery (許我個女性友達吧:))
看板C_Sharp
標題Re: [問題] 請問有誰會寫DEV-c++的程式
時間Tue Dec 7 00:10:04 2004
※ 引述《[email protected] (好累的恩....)》之銘言:
: ※ 引述《[email protected] (許我個女性友達吧:))》之銘言:
: > 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