c语言编程题:从键盘输入6个整数。存到数组中,统计其中偶数的个数 并计算8它们的和

2024-11-13 03:40:06
推荐回答(1个)
回答1:

#include 
int main(void){
        int arr[6]={};
        int num=0,sum=0;
        int i=0;
        while(i<6){
                scanf("%d",&arr[i]);
                if(arr[i]%2==0){
                        num++;
                        sum+=arr[i];
                }   
                i++;
        }   
        printf("偶数个数:%d\n",num);
        printf("偶数和:%d\n",sum);

}

输出结果:

0
1
2
35
6
7
偶数个数:3
偶数和:8

有问题请追问