使用函数求奇数和

来源:互联网 发布:网络男女对唱歌曲大全 编辑:程序博客网 时间:2024/06/05 04:13

#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;

}