First time here? Checkout the FAQ!
x
menu search
brightness_auto
more_vert

Write a program in C++ to find the Greatest Common Divisor (G.C.D.) of two natural numbers.

thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike

1 Answer

more_vert
 
verified
Best answer

//Program to find the G.C.D. of two numbers

#include<iostream.h>
#include<conio.h>
int gcd(int a, int b);
void main()
{
int x, y, g;
clrscr();
cout<<"Enter two numbers : "<<endl;
cin>>x>>y;
g=gcd(x,y);
cout<<"GCD of these numbers is : "<<g;
getch();
}

int gcd(int a, int b)
{
int r;
r=a%b;
while (r>0)
{
a=b;
b=r;
r=a%b;
}
return b;
}
thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike
...