求助
我是个新手,关于求和1+3-5+7-9+11..........101#include "stdio.h"
void main()
{
int s,i,t;
t=1;
for(s=0,i=1;i<=101;i+=2)
{
if(t%2==0)i=-i;
s+=i;
t++;
}
printf("%d",s);
}
又语法错误码,但最后陷入死循环,指点一下是错在哪了.
#include <stdio.h> int main(void) { int s = 1, i, t = 1; for (i = 3; i <= 101; t = !t, i += 2) s += t ? i : -i; printf("%d\n",s); printf("%d\n",1+(99+3)*((99-3)/4+1)/2-(101+5)*((101-5)/4+1)/2); printf("%d\n",1 + -(103-3)/2); return 0; }