Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

q12 Write a recursive function to calculate the cosine of a number using mathema

ID: 3810657 • Letter: Q

Question


q12

Write a recursive function to calculate the cosine of a number using mathematical formula (repeal 50 iteration) Write = recursive function lo calculate e^x using the mathematical formula (repeat 50 iteration) Write a recursive function to calculate the largest element In on array. Write a recursive function lo calculate the smallest element in an array, Write a recursive function lo ditch if a number it a palindrome.. Write a recursive function to calculate the n^th Fibonacci number.. Write a recursive function to calculate the gcd/lem of n numbers.

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);

}

}