c语言程序怎样用for循环计算1 2 3 .... 100

c语言程序怎样用for循环计算1 2 3 .... 100
2024-11-26 06:55:47
推荐回答(3个)
回答1:

1+2+3+...100 ?
int i, s;
for (i=1; i<=100; i++)
s=s+i;

printf("%d", s)

回答2:

#include"stdio.h"
void main ()
{
int sum=0;
int i;
for (i=1;i<=100;i++)
sum+=i;
printf("sum=%d",sum);
}

回答3:

1+2+3+...100 ?
int i, s=0;
for (i=1; i<=100; i++)
s=s+i;

printf("%d", s)