ds activity
ds activity
UNIVERSITY
Jnana Sangama, Belgavi-590018
Submitted by
NAME: Vishwanath V
USN: 1KS22EC121
CERTIFICATE
1. Abstract 1
2. Introduction to algorithm 2
3. Methodology 3
4. Code 4
5. Flow Chart 6
6. Results 7
7. References 7
1. ABSTRACT
1
2: Introduction to Euclidean Algorithm
2
3: Methodology
1.Consider any two number (a,b) the highest number of (a,b) will be considered
as dividend, the least number of (a,b) considered as divisor.
2.Divide the given number and find the quotient and remainder.
3.if R=0 stop the division and GCD for the given number will be divisor such
as b.
4.if R=0 continue the division considering the previous divisor value as
dividend and previous remainder as divisor continue the procedure until the
R=0.
3
4: Code
clc;
close all;
clear all;
N1 = input('Enter the first number: ');
N2 = input('Enter the second number: ');
N3 = abs(N1);
N4 = abs(N2);
if (N3 > N4)
a = N3;
b = N4;
else
a = N4;
b = N3;
end
GCD = gcd(a, b);
fprintf('The GCD of %d and %d is %d\n', N1, N2, GCD);
4
Explanation of the code:
1.Start fresh:
The first three lines clear old stuff to the program starts clean
2.Ask the user for two numbers:
The program asks you to enter two numbers(they can be positive or
negative).
3.Make both numbers positive:
It changes both numbers to positive, because GCD works with
positive values.
4.Find which number is bigger:
It checks which number is larger and stores them as a(bigger one)
and b(smaller one).
5.Find the GCD:
It uses MATLAB’s built-in gcd function to find the greatest number
that divides both a and b exactly.
6.Show the result:
It prints the GCD of the original two numbers you entered.
5
5: Flow Chart
Start
a divides b
No
Consider previous b value as
If r=0
a and previous r value as b
Yes
GCD=b
Stop
6
6: Results
Enter the first number: 156
Enter the second number: -5
The GCD of 156 and -5 is 1
7: References:
1.Stallings, w. Cryptography and Network Security: Principles and Practice (6th Edition)
2.Matrixlab-Examples (n.d.). Euclidean Algorithm with matlab
3. X. Zhu, X. Wu, W. Ben, and H. Zhou, "An Improved Fuzzy C-Means Clustering
Algorithm Using Euclidean Distance Function," Journal of Intelligent & Fuzzy
Systems, 2023, doi: 10.3233/JIFS-223576.
4. B. Hopkins and A. Tangboonduangjit, "Ties in Worst-Case Analysis of the Euclidean
Algorithm," Mathematical Communications, 2021, ISSN: 1331-0623.