#include <stdio.h>

int main() { int num, odd_count = 0, even_count = 0;

do {
    printf("请输入一个整数(输入0或负数表示结束):");
    scanf("%d", &num);
    if (num > 0) { // 只统计正整数
        if (num % 2 == 0) {
            even_count++;
        } else {
            odd_count++;
        }
    }
} while (num > 0);

printf("奇数的个数:%d\n", odd_count);
printf("偶数的个数:%d\n", even_count);

return 0;

}

用C 写一个程序从键盘输入一系列整数输入0或负数表示结束分别统计这些数里面的奇数偶数的个数要求使用do-while语句

原文地址: https://www.cveoy.top/t/topic/bYrh 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录