Experiment 4-1-2 Finding odd sums (15 points)

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:

Insert picture description here

Problem-solving ideas:

Not difficult! Not even a comment~

Guess you like

Origin blog.csdn.net/weixin_43862765/article/details/114476457