SNOWSD

导航

c语言学习路程——1~100的素数和

#include <stdio.h>

int main() {
    int m, n;
    int i;
    int count = 0;
    int sum = 0;
    scanf_s("%d %d", &m, &n);

    for (int i = m; i <= n; i++) {
        int isPrime = 1;

        int k;
        for (int k = 2; k <= i - 1; k++) {
            if (i % k == 0) {
                isPrime = 0;
                break;
            }
        }

        if (isPrime && i != 1) {
            count++;
            sum += i;
        }
        printf("sum=%d\n", sum);
//        printf("count=%d\n", count);

    }

}

 

posted on 2021-01-09 14:13  SNOWSD  阅读(652)  评论(0编辑  收藏  举报