Write a C++ program to find out GCD of given two numbers using function

Estudies4you
Q38.. Write a C++ program to find out GCD of given two numbers using function.
Answer :

Program
#include<iostream.h>
#include<conio.h>
int gcd(int a,int b);
int main()
{
int p, q;
clrscr();
cout<<“Enter the values of p and q:”;
cin>>p >>q;
cout<<“GCD of” <<“ "<< p<<“ "<< “and” <<“ ” << q <<“ "<< “is”<<“ "<< gcd(p,q);
getch();
return 0;
}
int gcd(int a,int b)
{
if(b==0)
return a;
else if(b>a)
return gcd(b,a);
else
return gcd(b,a%b);
}

Output
Write a C++ program to find out GCD of given two numbers using function,c++ notes,c++ lecture notes,c++ study material,c++ programs,c++ lab manual,jntuh c++ notes,oops through c++ lecture notes,oops using c++ lecture notes,oops notes,c++ course file,estudies4you

To Top