Skip to content
doubtly

1 answer

Best answer

image

//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;
}

getch for more older version of Turbo C++ compiler 
Enter two numbers :
40
20
GCD of these numbers is : 20 
Doubtly · 1 May 2021 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.