c语言程序设计试题 1-2+3-4...-100=?
4个回答
展开全部
这个题太简单了吧
#include <stdio.h>
int main()
{
int sum = 0, i, sign = 1;
for(i=1; i<=100; i++)
{
sum += sign*i;
sign *= -1;
}
printf("1-2+3-4....100 = %d\n", sum);
return 0;
}
#include <stdio.h>
int main()
{
int sum = 0, i, sign = 1;
for(i=1; i<=100; i++)
{
sum += sign*i;
sign *= -1;
}
printf("1-2+3-4....100 = %d\n", sum);
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
CLOSE ALL
CLEAR ALL
CLEAR
nTotalCount = 0
FOR nLoop_01 = 1 TO 100
IF MOD(nLoop_01, 2) = 1
nTotalCount = nTotalCount + nLoop_01
ELSE
nTotalCount = nTotalCount - nLoop_01
ENDIF
NEXT
?"S=1-2+3-4. . . . . .-100:", nTotalCount
*** 屏显:S=1-2+3-4. . . . . .-100: -50
RETURN
CLEAR ALL
CLEAR
nTotalCount = 0
FOR nLoop_01 = 1 TO 100
IF MOD(nLoop_01, 2) = 1
nTotalCount = nTotalCount + nLoop_01
ELSE
nTotalCount = nTotalCount - nLoop_01
ENDIF
NEXT
?"S=1-2+3-4. . . . . .-100:", nTotalCount
*** 屏显:S=1-2+3-4. . . . . .-100: -50
RETURN
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
for(i=1;i<=100;i++)
{
sum=sum+(-1)的(i+1)次方*i
}
{
sum=sum+(-1)的(i+1)次方*i
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询