中央論壇 - CENTER BBS
標題:
1-2+3-4+5-6.......一直至N
[打印本頁]
作者:
f66666602
時間:
2007-8-13 02:14
標題:
1-2+3-4+5-6.......一直至N
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int n,i,total1,total2,sum;
printf("\n請輸入整數n值:");
scanf("%d",&n);
total1=0;
total2=0;
sum=0;
for(i=1;i<=n)
{
if((i++ % 2)==0)
total1 += i;
else
total2 += i;
}
sum=total2-total1;
printf("1-2+3-4+5-6+-.....+-n值為:%d\n",sum);
system("PAUSE");
return EXIT_SUCCESS;
}
歡迎光臨 中央論壇 - CENTER BBS (https://www.centerbbs.com/)
Powered by Discuz! X3