Fidn the gcd of two numbers using recursion
Answers
Answered by
0
Public class GCD
{
public static void main (string args [])
{
int n1 =366, n2 =60 :
int hcf =hcf (n1, n2)
system. out. print f (GCD of percentage d and percentage d)
{
public static int hcf (n1, n2)
{
if (n2 is unequal to 0)
return hcf (n2 n1 percentage n2)
else
return n1
}
}
{
public static void main (string args [])
{
int n1 =366, n2 =60 :
int hcf =hcf (n1, n2)
system. out. print f (GCD of percentage d and percentage d)
{
public static int hcf (n1, n2)
{
if (n2 is unequal to 0)
return hcf (n2 n1 percentage n2)
else
return n1
}
}
Answered by
0
Answer:
#include <stdio.h>
int hcf(int n1, int n2);
int main() {
int n1, n2;
printf("Enter two positive integers: ");
scanf("%d %d", &n1, &n2);
printf("G.C.D of %d and %d is %d.", n1, n2, hcf(n1, n2));
return 0;
}
int hcf(int n1, int n2) {
if (n2 != 0)
return hcf(n2, n1 % n2);
else
return n1;
}
//c++ programming
#include<iostream>
using namespace std;
int hcf(int n1, int n2);
int main() {
int n1, n2;
cin>>n1>>n2;
cout<<"G.C.D of "<<n1<<" and "<<n2<<" = "<< hcf(n1, n2);
return 0;
}
int hcf(int n1, int n2) {
if (n2 != 0)
return hcf(n2, n1 % n2);
else
return n1;
}
Explanation:
Similar questions