/* This is HW3 performs prime factorization of a given
positive integer.
Creating the code and free of syntax and grammatical errors.
Author: Ekwegbalum Unachukwu
Star ID:do2170dt
Date: April 2nd, 2024.
*/
#include <stdio.h>

int main() {
    int num_EU, i_EU;
    
    // Prompt the user to enter a positive integer
    printf("Enter a positive integer: ");
    scanf("%d", &num_EU);

    printf("Prime factors of %d are: ", num_EU);

    i_EU = 2; // Start with the smallest prime number

    // Use a while loop to find and print all prime factors
    while (i_EU <= num_EU) {
        if (num_EU % i_EU == 0) {
            printf("%d ", i_EU);
            num_EU /= i_EU;
        } else {
            i_EU++; // Increment to the next potential factor
        }
    }
    
    return 0;
}

Embed on website

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