作者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