Re: [問題] 請問有誰會寫DEV-c++的程式
※ 引述《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
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 4 之 7 篇):