【问题描述】
读入一批正整数(以零或负数为结束标志),求其中的奇数和。请使用while 语句实现循环。
【输入形式】
从键盘输入一批正整数(以0或负数为结束标志)。
【输入输出样例1】(下划线部分表示输入)
Input integers: 1 3 90 7 0
The sum of the odd numbers is 11
【输入输出样例2】(下划线部分表示输入)
Input integers: 2 7 88 37 90 9 -1
The sum of the odd numbers is 53
【样例说明】
输入提示符后要加一个空格。例如“Input integers: ”,其中“:”后要加一个且只能一个空格。
输入的数据之间以一个空格相隔。
输出语句的“is”后面加一个且只能加一个空格。
英文字母区分大小写。必须严格按样例输入输出。
#include <stdio.h>
int main()
{
int num;
int sum=0;
printf("Input integers: ");
scanf("%d",&num);
while(num>0)
{
if(num%2==0)
{
num=0;
}
sum+=num;
scanf("%d",&num);
}
printf("The sum of the odd numbers is %d",sum);
return 0;
}