q12 Write a recursive function to calculate the cosine of a number using mathema
ID: 3810657 • Letter: Q
Question
q12
Explanation / Answer
import java.util.*;
import java.lang.*;
import java.io.*;
class GCD
{
private static int gcd(int number1, int... otherNumbers) //In java which stores al the number using int…
{
int result = number1;
for(int number: otherNumbers)
result = gcd(result, number);
return result;
}
private static int gcd(int a, int b, int c, int d, int e)
{
return gcd(gcd(a, b), gcd(gcd(c, d), e));
}
private static int gcd(int number1, int number2) //Finds GCD of 2 numbers.
{
if(number2 == 0)
{
return number1;
}
return gcd(number2, number1%number2);
}
public static void main (String[] args) throws java.lang.Exception
{
int num1=gcd(2,88,12,56,54,100);
int num2=gcd(3,33,99);
System.out.println("gcd of first set of number is "+num1+" GCD of second set of nnumbers is "+num2);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.