相关代码{
相关代码:
#define MAXN 10//把MAXN定义为常量10
int even( int n );
int OddSum( int List[], int N );
int main()
{
int List[MAXN], N, i;
scanf("%d", &N);
printf("Sum of ( ");
for ( i=0; i<N; i++ ) {
scanf("%d", &List[i]);
if ( even(List[i])==0 )//调用even函数,当 even(List[i])==0,判断为奇数
printf("%d ", List[i]);//打印奇数
}
printf(") = %d\n", OddSum(List, N));
return 0;
}
int even( int n ){
if(n%2==0){
return 1;
}
else{
return 0;
}
}
int OddSum( int List[], int N ){
int sum=0;
int l=0;
for(l=0;l<N;l++){
if(even(List[l])==0){
sum=sum+List[l];
}
}
return sum;
}