/* This is the tenth lab of Lab EE107
The purpose of this lab for finding the greatest common divisor
of two nonnegative integer values by calling a function that returns
an integer.
Creating the code and free of syntax and grammatical errors.
Author: Ekwegbalum Unachukwu
Star ID:do2170dt
Date: April 2nd, 2024.
*/
#include <stdio.h>
// Function to calculate the greatest common divisor (GCD)
int calculateGCD_Eu(int a_Eu, int b_Eu) {
int temp_Eu;
while (b_Eu != 0) {
temp_Eu = b_Eu;
b_Eu = a_Eu % b_Eu;
a_Eu = temp_Eu;
}
return a_Eu;
}
int main() {
int num1_Eu, num2_Eu;
// Input two non-negative numbers
printf("Enter two non-negative numbers to find their greatest common divisor (GCD):\n");
printf("Number 1: ");
scanf("%d", &num1_Eu);
printf("%d",num1_Eu);
printf("\nNumber 2: ");
scanf("%d", &num2_Eu);
printf("%d",num2_Eu);
// Validate inputs
if (num1_Eu < 0 || num2_Eu < 0) {
printf("Please enter non-negative integers.\n");
return 1; // Exit with error code
}
// Calculate GCD
int gcd_Eu = calculateGCD_Eu(num1_Eu, num2_Eu);
// Display the result
printf("\nThe greatest common divisor (GCD) of %d and %d is: %d\n", num1_Eu, num2_Eu, gcd_Eu);
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: