You are on page 1of 4

Experiment Title

Student Name: Shaurav Suman Kumar UID:19BCS2201


Branch: CSE Section/Group 8-C
Semester: 5th Date of Performance:16-08-2021
Subject Name: DESIGN & ANALYSIS OF ALGORITHMS LAB
Subject Code: CSP-309

1. 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: C++/Online GDB compiler

3. Algorithm/Flowchart (For programming based labs):

Pseudo Code of the Algorithm-


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
C++ Code to Perform GCD-

int gcd(int a,int b) {


int R;
while ((a % b) > 0) {
R = a % b;
a = b;
b = R;
}
return b;

4. Steps for experiment/practical/Code:

#include <iostream>
using namespace std;

int gcd(int a, int b)


{
if (a == 0)
return b;
if (b == 0)
return a;

if (a == b)
return a;

if (a > b)
return gcd(a-b, b);
return gcd(a, b-a);
}
int main()
{
int a = 92, b = 86;
cout<<"GCD of "<<a<<" and "<<b<<" is "<<gcd(a, b);
return 0;
}

5. Observations/Discussions/ Complexity Analysis:

6. Result/Output/Writing Summary:
Learning outcomes (What I have learnt):

1. We learned about gcd algorithm


2. We learned about euclidean algorithm
3. We learned about new algorithms
4. We learned about gcc compiler
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