Question: Please code the following methods in C#: EvenOdd Write a recursive function that determines if a number is even or odd. Your function should take
Please code the following methods in C#:
EvenOdd
Write a recursive function that determines if a number is even or odd. Your function should take in one integer input and return if it is odd or even. You can assume that the correct type will be passed to the function. You must use recursion. Do NOT use the Modulus (%) operator.
EvenOdd(5);
Odd
EvenOdd(10);
Even
EvenOdd(255);
Odd
EvenOdd(1250);
Even
EvenOdd(0);
Even
MyMathFunction
Write a function that takes in two numbers and a function name. The function should call the function name in the parameter passing it the two number to perform a math operation and returning the result. Your MyMathFunction should be able to handle 4 different math operations (add, subtract, divide, and multiply). You must write 5 functions to complete this assignment correctly (MyMathFunction, Add, Subtract, Multiply, Divide). Hint: Do not pass the function name as a string. Look at Delegates.
MyMathFunction(10, 10, Multiply);
100
MyMathFunction(50, 10, Divide);
5
MyMathFunction(10, 0, Divide);
Cannot Divide by 0!
MyMathFunction(20, 25, Add);
45
MyMathFunction(25, 20, Subtract);
5
SortMyArray
Write a function that takes in an array of integers and sorts the array from smallest to largest. Your function should return an array with the sorted list and print the list out. You can assume that the array being passed will always have integers (You do not need to type check the array). DO NOT USE the built-in array sort function.
var arr1=[-3,8,7,6,5,-4,3,2,1];
SortMyArray(arr1);
[ -4, -3, 1, 2, 3, 5, 6, 7, 8 ]
var test_array=[1,2,3,4,5];
SortMyArray(test_array);
[ 1,2,3,4,5]
var test_array=[];
SortMyArray(test_array);
Cannot sort an Empty Array!
var test_array=[1,-1,-2,2,3,-3,-4,4,5,-5,0];
SortMyArray(test_array);
[ -5,-4,-3,-2,-1,0,1,2,3,4,5]
var test_array=[1, 1, 1, 100, 75, 2, 2, 37, 55, 55];
SortMyArray(test_array);
[1,1,1,2,2,37,55,55,75,100]
myFib
Write a C# function using recursion to compute the Fibonacci number of n (where n is a positive integer). Your function should output the calculated result for the n given. You do not need to type check and can assume the value being given is an integer.
Fib(n) = 1 for n = 0 or n = 1
Fib(n) = Fib(n-1) + Fib(n-2) for n > 1
myFib(5);
8
myFib(10);
89
myFib(8);
34
myFib(45);
1836311903
myFib(0);
1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
