奇数偶数和-while()结构

2024-02-02 20:25:45 浏览数 (1)

代码语言:javascript复制
#include <stdio.h>
#include <math.h>//fabs
#include <stdlib.h>//abs

int main() {
    int i = 1, sum_odd = 0, sum_even = 0;
    while (i <= 20) {
        if (i % 2 == 0)
            sum_even = sum_even   i;
        else
            sum_odd = sum_odd   i;
        i  ;
    }
    printf("偶数和%d,奇数和%d", sum_even, sum_odd);
    return 0;
}

0 人点赞