1. 程式人生 > >使用函式求奇數和

使用函式求奇數和

#include <stdio.h>

int even(int n);

int main(void)

{

    int n,t,sum=0;

    while(n>0)

    {

        scanf("%d",&n);

        t=even(n);

        if(t==0)

            sum=sum+n;

    }

    printf("The sum of the odd numbers is %d",sum);

    return 0;

}

int even(int n)

{

    if(n%2==1)

        return 0;

    else

        return 1;

}