Problem 4-1 seeking odd and (15 minutes)

This problem requires calculation of a given set of odd positive integers and.

Input formats:

Gives a positive integer in the range of the input line, separated by a space therebetween. When read zero or negative integer representing the input end, the numbers do not deal with.

Output formats:

In a row in the output sequence of positive integers and odd.

Sample input:

8 7 4 3 70 5 6 101 -1

 

Sample output:

116

answer:

#include<stdio.h>
int main(){
    int n,sum=0;
    while(~scanf("%d",&n)&&n>0){
        if(n%2!=0) sum+=n;
    }
    printf("%d",sum);
    return 0;
}

 

Published 98 original articles · won praise 2 · Views 3736

Guess you like

Origin blog.csdn.net/qq_30377869/article/details/104754259