**Wipro Coding Questions**

**Q1. Write a program to print Fibonacci Series using recursion, where n is the input to the program and n>0.**

**Fibonacci Series: It represents sum of the preceding two numbers. In this program, we are printing the Fibonacci series: Fibonacci series in a given range n .Ex:n= 4 Series: 0 1 1 2**

**Input Format:**

**A single integer n**

**Output Format:**

**The output is the Fibonacci series without spaces.**

**Constraints:**

**n > 1**

**Sample Input:**

**5**

**Sample Output:**

**01123**

**Explanation:**

**First we have to take the number of terms n as input from user then we are calling user defined function fib(n). Fib(n) recursive function we calculate the (n-1)th and (n-2)th Fibonacci numbers then add those numbers to get the nth Fibonacci number. By using for loop we are printing the n terms of Fibonacci series.**

**Solution Code:**

**#include <stdio.h>**

**int fib(int n)**

**{**

**if(n == 0 || n==1)**

**{**

**return n;**

**}**

**else**

**{**

**return fib(n-1) + fib(n-2);**

**}**

**}**

**int main()**

**{**

**int i,n;**

**scanf(“%dt”,&n);**

**for(i=0;i<n;i++)**

**{**

**printf(“%d”,fib(i));**

**}**

**return 0;**

**}**

**Explanation:**

**Fibonacci Series: It represents sum of the preceding two numbers. In this program we are printing the Fibonacci series in a given range n. Ex:n= 4 Series: 0 1 1 2.**

**Recursion: A function called by it self is called recursion. We are using recursion for many mathematical problems and logical problems like factorial and towers of Hanoi, Fibonacci.**

**We are using a user-defined function Fib() which takes an integer n as input and returns the n terms of Fibonacci series by using recursion.**

**The recursion will terminate when number of terms less than because we know the first two terms of Fibonacci series are 0 and 1.Else calculate the (n-1)th and (n-2) th Fibonacci numbers then add those numbers to get the nth Fibonacci number.**

**int fib(int n)**

**{**

**if(n == 0 || n==1)**

**{**

**return n;**

**}**

**else**

**{**

**return fib(n-1) + fib(n-2);**

**}**

**}**

**First we have to take the number of terms of Fibonacci series by using scanf function .****By using for loop we are printing the n terms of Fibonacci series by calling Fib() function recursively**

**int i,n;**

**scanf(“%dt”,&n);**

**for(i=0;i<n;i++)**

**{**

**printf(“%d”,fib(i));**

**}**

**Q2.Write a program to find maximum and minimum elements in an array. The input will be number of elements in array and the array elements.**

**Arrays: Arrays are used to store the elements with the same data type.**

**Input Format:**

**The first line takes the input n represents the array size.**

**The second line represents the array elements each element on a new line.**

**Output Format:**

**The output is the maximum and minimum elements in an array each element on a new line.**

**Constraints:**

**n > 0**

**Sample Input :**

**10**

**-10**

**10**

**0**

**20**

**-2**

**50**

**100**

**20**

**-1**

**10**

**Sample Output :**

**100**

**-10**

**Explanation:**

**First, we have to take the size of the array n and array elements as an input. Declare two variables max and min to store maximum and minimum. Assume first array element as maximum and minimum both, then assign max =arr[0] and min = arr[0].Then iterate through the array to find max and min element in the array. Run a loop from 1 to n. Ifarr[i] < min then print arr[i] as min element and If arr[i] > max then print arr[i] as max element.**

https://www.mayanksinghkushwah.in/