输入n个数,请数出当中一共有多少个奇数。具体要求如下!

img


#include <iostream>
using namespace std;
int main()
{
    int n; cin >> n;
    int res = 0;
    for (int i = 0; i < n; i++)
    {
        int a; cin >> a;
        if (a % 2 != 0)
        {
            res++;
        }
    }
    cout << res << endl;
    return 0;
}

img

供参考:

#include <stdio.h>
int main()
{
    int n, m, cnt = 0;
    scanf("%d", &n);
    while (n--)
    {
        scanf("%d", &m);
        if (m % 2 == 1) cnt++;
    }
    printf("%d", cnt);
    return 0;
}