3.x[12]={2,45,67,12,3,9,76,45,23,42,6,5},编程实现数组x中奇数的个数及奇数之和
时间: 2023-08-19 22:15:02 浏览: 131
java源代码--求n个奇数的和
以下是实现数组x中奇数的个数及奇数之和的C代码:
```c
#include <stdio.h>
int main() {
int x[12] = {2, 45, 67, 12, 3, 9, 76, 45, 23, 42, 6, 5};
int odd_count = 0, odd_sum = 0;
for (int i = 0; i < 12; i++) {
if (x[i] % 2 == 1) {
odd_count++;
odd_sum += x[i];
}
}
printf("奇数的个数为:%d,奇数之和为:%d\n", odd_count, odd_sum);
return 0;
}
```
输出结果为:
```
奇数的个数为:5,奇数之和为:187
```
阅读全文