/*This is the eighth lab of Lab EE107
The purpose of this lab understand how a program (if else) that checks prime number
and print out the result.
Creating the code and free of syntax and grammatical errors.
Author: Ekwegbalum Unachukwu
Star ID:do2170dt
Date: March 19th, 2024.
*/
#include <stdio.h>
#include <math.h>

int main() {
    printf("Prime numbers up to 50:\n");
    
    // Iterate through numbers from 2 to 50
    for (int n_EU = 2; n_EU <= 50; n_EU++) {
        int is_prime = 1; // Assume the number is prime initially
        
        // Check if the current number is divisible by any number from 2 to its square root
        for (int j = 2; j <= sqrt(n_EU); j++) {
            if (n_EU % j == 0) {
                is_prime = 0; // It's not prime if it's divisible
                
            }
        }
        
        // If the number is still marked as prime, print it
        if (is_prime) {
            printf("%d ", n_EU);
        }
    }
    
    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: