Computer Science, asked by nathandias177, 10 months ago

write a program in c++ to accept 2 integers and find its G.C.D using function with return statement

Answers

Answered by gurkanwal2007
2

Answer:

could not understand question

Answered by ridhimakh1219
1

Write a program in c++ to accept 2 integers and find its G.C.D using function with return statement

Explanation:

C++ program to find GCD of two number using function with return statement.

#include<iostream>

#include<conio.h>

using namespace std;

int gcd(int x,int y); // function prototype

int main()

{

int a,b;

cout<<"Enter two numbers : ";

cin>>a>>b;

cout<<"The GCD of "<<a<<" and "<<b<<" is "<<gcd(a,b);

getch();

return(0);

}

// function definition

int gcd(int x,int y)

{

int z=x%y;

if(z==0)

return(y);

else

return(gcd(y,z)); // recursive call

}

Output

Enter two numbers : 10

4

The GCD of 10 and 4 is 2  

Similar questions