This question requires calculating the sum of odd numbers in a given series of positive integers.
Input format:
Input gives a series of positive integers on one line, separated by spaces. When a zero or negative integer is read, it means the input is over, and the number should not be processed.
Output format:
Output the sum of odd numbers in a sequence of positive integers in one line.
Input sample:
8 7 4 3 70 5 6 101 -1
Sample output:
116
Code:
# include <stdio.h>
# include <stdlib.h>
int main() {
int number,value = 0;
while(1) {
scanf("%d",&number);
if (number <= 0) {
break;
}else {
if (number % 2 == 1) {
value += number;
}
}
}
printf("%d",value);
return 0;
}
Submit screenshot:
Problem-solving ideas:
Not difficult! Not even a comment~