Generate a table of prime numbers. - C Statement

C examples for Statement:for

Description

Generate a table of prime numbers.

Demo Code

#include <stdio.h>

int main (void)
{
    int p, d;//from  ww  w .  ja va  2 s .  c o m
    bool isPrime;

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

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

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

    printf ("\n");

    return 0;
}

Result


Related Tutorials