0% found this document useful (0 votes)
58 views4 pages

Experiment Title: Algorithm/Flowchart

The document summarizes a student's experiment to compute the greatest common divisor (GCD) of two numbers. The student: 1) Coded an algorithm to calculate the GCD using the Euclidean algorithm. 2) The algorithm takes two numbers as input and recursively calculates their modulus until one is 0, at which point the other number is the GCD. 3) The student observed the time complexity of the algorithm is O(logn) and provided sample output of "GCD of 58 and 28 is 2."

Uploaded by

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

Experiment Title: Algorithm/Flowchart

The document summarizes a student's experiment to compute the greatest common divisor (GCD) of two numbers. The student: 1) Coded an algorithm to calculate the GCD using the Euclidean algorithm. 2) The algorithm takes two numbers as input and recursively calculates their modulus until one is 0, at which point the other number is the GCD. 3) The student observed the time complexity of the algorithm is O(logn) and provided sample output of "GCD of 58 and 28 is 2."

Uploaded by

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

Experiment Title

Student Name: Shreyansh Raut UID: 18BCS1703


Branch: CSE Section/Group- NTTP-2[A]
Semester: 5 Date of Performance: 2020-7-29
SUBJECT NAME: DAA LAB SUBJECT CODE: CSP-309

Aim/Overview of the practical: Code and analyze to compute the greatest common divisor
(GCD) of two numbers.

2. Task to be done/ Which logistics used: The greatest common divisor (gcd) of two or more
integers, which are not all zero, is the largest positive integer that divides each of the integer.

We use the euclid formula for calculating GCD


GCD(a,b)=GCD(b,a%b)

3. Algorithm/Flowchart

Step 1: Let a, b be the two numbers

Step 2: a mod b = R

Step 3: Let a = b and b = R

Step 4: Repeat Steps 2 and 3 until a mod b is greater than 0

Step 5: GCD = b
Step 6: Finish

4. Steps for experiment/practical/Code:

#include <iostream>

using namespace std;

int gcd(int a, int b);

int main()

int a, b;

cout << "Enter two positive integers: ";

cin >> a >> b;

cout << "GCD of " << a << " & " << b << " is: " << gcd(a, b);

return 0;

int gcd(int a, int b)

if (b != 0)

return gcd(b, a % b);

else

return a;
}

5. Observations/Discussions/ Complexity Analysis:


O(logn) is the complexity.

6. Result/Output/Writing Summary:
Output:GCD of 58 and 28 is 2.

Learning outcomes (What I have learnt):


1. How to find time complexity

2.How to translate algo into code format

3. To find complexity of gcd

Evaluation Grid (To be created as per the SOP and Assessment guidelines by the faculty):

Sr. No. Parameters Marks Obtained Maximum Marks


1.
2.
3.

You might also like