/* This is HW4 Lab EE107
The purpose of this generate prime numbers 
Creating the code and free of syntax and grammatical errors.
Author: Ekwegbalum Unachukwu
Star ID:do2170dt
Date: April 17th, 2024.
*/


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


int main(void) {
    //initialization of the variables of the prime numbers where prime index is 2 and the array size of 50
    int p, i, primes[50], primeIndex = 2;
        //initialze the bool variable
    bool isPrime;

    //Using the array index to assign values
    primes[0] = 2;
    primes[1]= 3;

    // for loop for p determing prime numbers
    for (p = 5 ; p <= 50 ; p = p + 2 ) {
        isPrime = true;
         // interation for the array primes from i= 1 to i = 50
        for (i = 1; isPrime && p / primes[i] >= primes[i]; ++i ) {
                if (p % primes[i] == 0)
                    isPrime = true;
//storing all the values that are prime numbers in "p" from the indices
        if( isPrime == true){
            primes[primeIndex] = p;
            ++primeIndex;
        }
        }
        
    }
    for (i = 0; i < primeIndex ; ++i ) {
        printf("%i ",primes[i]);
    }

    printf("\n");

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: