/* This is the seventh lab of Lab EE107
The purpose of this lab is to understand how a program calculates the greatest
common divisor (gcd) between two integers u and v.
Creating the code and free of syntax and grammatical errors.
Author: Ekwegbalum Unachukwu
Star ID: do2170dt
Date: March 12th, 2024.
*/

#include <stdio.h>

int main() {
    // Input values for u and v
    int u_EU, v_EU;
    printf("Enter the value for u: \n");
    scanf("%d", &u_EU);
    
    printf("Enter the value for v: \n");
    scanf("%d", &v_EU);

    // Calculate gcd without a separate function
    while (v_EU != 0) {
        int temp = u_EU % v_EU;
        u_EU = v_EU;
        v_EU = temp;
    }

    // Ensure the result is non-negative
    int result = (u_EU < 0) ? -u_EU : u_EU;

    // Print the result
    printf("The greatest common divisor (gcd) of %d and %d is: %d\n", u_EU, v_EU, result);

    return 0;
}

Embed on website

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