Generate a table of prime numbers. - C Data Type

C examples for Data Type:int

Description

Generate a table of prime numbers.

Demo Code

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

int main (void){
    bool isPrime;

    for (int p = 3; p <= 50; p += 2)
    {//from  w w w  .  j a  v  a 2 s.  c  o  m
        isPrime = true;

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

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

Result


Related Tutorials