Documentation Euclidean Algorithm

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

I.

Introduction

The Euclidean algorithm is a way to find the greatest common divisor of two positive integers, a and b.
First let me show the computations for a=210 and b=45. Divide 210 by 45, and get the result 4 with
remainder 30, so 210=4·45+30. Divide 45 by 30, and get the result 1 with remainder 15, so 45=1·30+15.

II. Objective

to find the GCD of two numbers. It cannot be directly applied to three or more numbers at a time.

III. Pseudocode/Algorithm

1. System will ask to type two integers to find the GCD

2. Enter the first integers for the GCD

3. Enter the second integers for the GCD

4. End The Program

IV. Flowchart
V. Program Codes/Syntax

#include <stdio.h>

int gcd(int a, int b) {

int temp;

while (b != 0) {

temp = b;

b = a % b;

a = temp;

return a;

int main() {

int a, b;

printf("Enter two integers to find their GCD: ");

scanf("%d %d", &a, &b);

printf("GCD of %d and %d is %d\n", a, b, gcd(a, b));

return 0;

VI. Output/Result

You might also like