4-10
4-10的任务代码怎么输
include <stdio.h>
int main()
{
int sum = 0;
int i = 1;
int flag = 1;
while(i<=100)
{
i++;
sum+=i*flag;
flag*=-1;
}
printf("sum=%d\n",sum);
return 0;
}
int sum=0;
int i = 1;
int flag = 1;
do{
i++;
sum+=i*flag;
flag*=-1;
}while(i<=100);
printf("sum=%d\n",sum);
return 0;
}
i = 1;
int sum = 0;
int i = 1;
int flag = 1;
for(i=1;i<=100;i++)
{sum+=i*flag;
flag*=-1;
}
printf("sum=%d\n",sum);
return 0;
}
举报