/* This is the ninth lab of Lab EE107
The purpose of this lab understand how a program determine the
primes that are less than
50 by using array
Creating the code and free of syntax and grammatical errors.
Author: Ekwegbalum Unachukwu
Star ID:do2170dt
Date: March 25th, 2024.
*/
#include <stdio.h>
#include <stdbool.h> // Include header for boolean data type
int main() {
int n_EU = 50; // Define the limit for prime numbers
bool is_prime_EU[50] = {false}; // Array to mark prime numbers, initialized with false
// Mark numbers 0 and 1 as not prime
is_prime_EU[0] = is_prime_EU[1] = true;
// Mark multiples of primes as not prime
for (int i_EU = 2; i_EU * i_EU < n_EU; i_EU++) {
if (!is_prime_EU[i_EU]) {
// Start marking multiples of current prime number as not prime
// Starting from square of the prime number since all multiples before that have already been marked
for (int j_EU = i_EU * i_EU; j_EU < n_EU; j_EU += i_EU) {
is_prime_EU[j_EU] = true; // Marking as not prime
}
}
}
printf("Prime numbers less than %d are:\n", n_EU);
// Print prime numbers
for (int i_EU = 2; i_EU < n_EU; i_EU++) {
if (!is_prime_EU[i_EU]) { // If the number is marked as prime
printf("%d ", i_EU); // Print the prime number
}
}
printf("\n");
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: