0% found this document useful (0 votes)
10 views3 pages

GCD (67

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

GCD (67

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Exp.

no: GCD using Euclidean algorithm


Date:

Aim:

To write a c code for execute GCD using Euclidean algorithm.

Algorithm:

Step 1: Define a function to compute the GCD using the Euclidean algorithm.

Step 2: Prompt the user to enter two integers.

Step 3: Read the integers from the user.

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.

You might also like