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

Maharashtra board

Maharashtra board

+1 vote

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

Maharashtra board

Maharashtra board

+1 vote

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;

}

getch for more older version of Turbo C++ compiler

Enter two numbers :

40

20

GCD of these numbers is : 20

40

20

GCD of these numbers is : 20

- All categories
- Doubt 0
- JEE-main 264
- MHT-CET 22
- maharashtra state board 230
- 11th Science Maharashtra Board 86
- 12th Science Maharashtra Board 32
- questionhub 3
- general 7
- computerscience 36
- Exam papers 10
- MOCK TEST 2
- Uncategorized 11
- Writing Skill 11

714 questions

695 answers

11 comments

24 users