C程程序填空题:输入一批正整数(以零或负数为结束标志),求其中的偶数和。

程序填空,不要改变与输入输出有关的语句。

输入一个正整数 repeat (0<repeat<10),做 repeat 次下列运算:
输入一批正整数(以零或负数为结束标志),求其中的偶数和。
输入输出示例:括号内为说明
输入
2 (repeat=2)
1 3 90 7 0
8 7 4 3 70 5 6 101 -1
输出
The sum of the even numbers is 90.
The sum of the even numbers is 88.

#include <stdio.h>
int main(void)
{
int sum, x;
int repeat, ri;

scanf("%d", &repeat);
for(ri = 1; ri <= repeat; ri++){
scanf("%d", &x);
/*---------*/
printf("The sum of the even numbers is %d.\n", sum);
}
}

第1个回答  2013-04-05
#include<stdio.h>
void main()
{
int x,sum=0;
do
{
scanf("%d",&x);
if(x>0&&x%2==0)
sum+=x;
}while(x>0);
printf("%d",sum);
}
第2个回答  2013-04-05
填入:
sum=0;
while (x > 0){
if ( x%2 == 0) sum=sum+x;
scanf("%d", &x);
}本回答被提问者和网友采纳

相关了解……

你可能感兴趣的内容

大家正在搜

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网