求1到100之间的偶数之和 用do.....while.....编写 c语言

2024-11-26 23:22:27
推荐回答(3个)
回答1:

#include
void main()
{
int i = 2,sum = 0;
do
{
sum += i;
i += 2;
}while(i <= 100);
printf("%d\n",sum);
}

回答2:

int r = 0;
int x = 1;
do
{
if (x % 2 == 0)
{
r += x;
}
} while(++x <= 100);

回答3:

main()

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