Generate a table of prime numbers, using bool type - C Statement

C examples for Statement:for

Description

Generate a table of prime numbers, using bool type

Demo Code

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

int main (void)
{
    int p, d;/*from  w  w w. j a v a2s. co m*/
    bool isPrime;

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

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

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

    printf ("\n");

    return 0;
}

Result


Related Tutorials