C语言while循环编程输出1到100这100个数的和!

快快快!!!!!!!
2024-11-09 17:48:00
推荐回答(3个)
回答1:

int i,sum;
i=1,sum=0;
while(i<=100)
{ sum+=i*i;//初始sum=0,每次循环,sum=sum+i*i
i+=1;
}

回答2:

int cou = 0;
int num = 0;
while (num <= 100)
{
cou = cou + num;
num++;
}

回答3:

main()
{
int i,sum;
i=1;
sum=0;
while(i<=100)
{
sum+=i;
i++;
}
printf("%d\n",sum);
}