GCD (67
GCD (67
Aim:
Algorithm:
Step 1: Define a function to compute the GCD using the Euclidean algorithm.
Step 4: Compute the GCD of the integers and print the result.
Program:
#include <stdio.h>
int gcd(int a, int b) {
while (b != 0) {
int temp = b;
b = a % b;
a = temp;
}
return a;
}
int main() {
int num1, num2;
printf("Enter two integers: ");
scanf("%d %d", &num1, &num2);
int result = gcd(num1, num2);
printf("GCD of %d and %d is %d\n", num1, num2, result);
printf("\nrrn:220171601067");
return 0;
}
Output:
Review Questions:
Result:
Thus, the program to execute GCD using Euclidean algorithm has been successfully verified and
executed.