+1 vote
3.0k views
in Programming by (98.9k points)
reopened by
Write a program in C++ to find the Greatest Common Divisor (G.C.D.) of two natural numbers. [March 2006]

Maharashtra board

1 Answer

+1 vote
by (98.9k points)
selected by
 
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 

Related questions

0 votes
1 answer 357 views
0 votes
1 answer 433 views
0 votes
1 answer 1.3k views

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

559 users

...