6. 编程实现:从键盘输入若干个正整数,求其中所有偶数的和并输出。输入的数以0作为结束标记。(思考

6. 编程实现:从键盘输入若干个正整数,求其中所有偶数的和并输出。输入的数以0作为结束标记。(思考C语言编程

#include <stdio.h>

int main()
{
int num=0,total =0;
do{
scanf("%d",&num);
if (num%2==0)
{
total += num;
}
}while (num!=0);
printf("total is [%d]\n",total);
return 0;
}
1
2
3
4
5
6
7
8
9
0
total is [20]

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答