生成素数表

#include stdio.h#include stdbool.hint main (void){bool isPrime;for (int p = 3; p = 50; p += 2)

编程学习网为您整理以下代码实例,主要实现:生成素数表,希望可以帮到各位朋友。

#include <stdio.h>
#include <stdbool.h>

int main (voID){
    bool isPrime;

    for (int p = 3; p <= 50; p += 2)
    {
        isPrime = true;

        for (int d = 2; d < p; ++d && isPrime)
            if (p % d == 0)
                isPrime = false;

        if (isPrime != false)
            printf ("%i ", p);
    }
    return 0;
}

本文标题为:生成素数表

基础教程推荐