__Description:__
GCD means Greatest Common Divisor.
i.e the highest number which divides the given number

Ex: GCD(12,24)
is 12

Formula: GCD=
product of numbers/ LCM of numbers

**main program**

__Algorithm:__
Step 1: start

Step 2: read
a,b

Step 3: call
the sub program GCD(a,b) for print the value

Step 4: stop

__Sub program:__
Step 1: if n>m
return GCD(n,m)

Step 2: if
n==0 return m else goto step 3

Step 3: return
GCD (n,m%n)

Step 4: return
to main program

__Program:__
#include<stdio.h>

#include<conio.h>

int gcdrecursive(int m,int n) // starting of the sub program

{

if(n>m)

return gcdrecursive(n,m);

if(n==0)

return m;

else

return gcdrecursive(n,m%n); // return to the
main program

}

void main()

{

int a,b,igcd;

clrscr();

printf("enter the two numbers whose gcd
is to be found:");

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

printf("GCD of a,b is %d",gcdrecursive(a,b)); // return to the
sub program

getch();

}

__Output:__
1. enter the two numbers whose gcd
is to be found:5,25

GCD of a,b is : 5

2. enter the two numbers whose gcd
is to be found:36,54

GCD of a,b is : 18

3. enter the two numbers whose gcd
is to be found:11,13

GCD of a,b is : 1

__Conclusion:__
The program is error free

__VIVA QUESATIONS:__
1) What
is meaning of GCD ?

Ans: GCD means Greatest Common
Divisor. i.e the highest number which divides

the given number

2) Define
scope of a variable ?

Ans: The scope of a variable can be define as the region over which the
variable is

accessible

3) Show
an scope resolution operator ?

Ans: double colon(

**::**)

4) Define
extent of a variable ?

Ans: The period
of time during which memory is associated with a variable is called

extent
of the variable.

## No comments:

## Post a Comment