# C# Sharp Recursion : Exercises, Practice, Solution

## C# Sharp Recursion [15 exercises with solution]

[** An editor is available at the bottom of the page to write and execute the scripts.** Go to the editor]

**1.** Write a program in C# Sharp to print the first n natural numbers using recursion.

Test Data* :
*How many numbers to print : 10

*:*

Expected Output

Expected Output

1 2 3 4 5 6 7 8 9 10

Click me to see the solution

**2.** Write a program in C# Sharp to print numbers from n to 1 using recursion.

Test Data* :
*How many numbers to print : 10

*:*

Expected Output

Expected Output

10 9 8 7 6 5 4 3 2 1

Click me to see the solution

**3.** Write a program in C# Sharp to find the sum of the first n natural numbers using recursion.

Test Data* :
*How many numbers to sum : 10

*:*

Expected Output

Expected Output

The sum of first 10 natural numbers is : 55

Click me to see the solution

**4.** Write a program in C# Sharp to display the individual digits of a given number using recursion.

Test Data* :
*Input any number : 1234

*:*

Expected Output

Expected Output

The digits in the number 1234 are : 1 2 3 4

Click me to see the solution

**5.** Write a program in C# Sharp to count the number of digits in a number using recursion.

Test Data* :
*Input any number : 12345

*:*

Expected Output

Expected Output

The number 12345 contains number of digits : 5

Click me to see the solution

**6.** Write a program in C to print even or odd numbers in a given range using recursion.

Test Data* :
*Input the range to print starting from 1 : 20

*:*

Expected Output

Expected Output

All even numbers from 1 to 20 are :

2 4 6 8 10 12 14 16 18 20

All odd numbers from 1 to 20 are :

1 3 5 7 9 11 13 15 17 19

Click me to see the solution

**7.** Write a program in C# Sharp to check whether a number is prime or not using recursion.

Test Data* :
*Input any positive number : 37

*:*

Expected Output

Expected Output

The number 37 is a prime number.

Click me to see the solution

**8.** Write a program in C# Sharp to check whether a given string is a palindrome or not using recursion.

Test Data* :
*Input a string : RADAR

*:*

Expected Output

Expected Output

The string is Palindrome.

Click me to see the solution

**9.** Write a program in C# Sharp to find the factorial of a given number using recursion.

Test Data* :
*Input any positive number : 5

*:*

Expected Output

Expected Output

The factorial of 5 is : 120

Click me to see the solution

**10.** Write a program in C# Sharp to find the Fibonacci numbers for a series of n numbers using recursion.

Test Data* :
*Input number of terms for the Fibonacci series : 10

*:*

Expected Output

Expected Output

The Fibonacci series of 10 terms is : 0 1 1 2 3 5 8 13 21 34

Click me to see the solution

**11.** Write a program in C# Sharp to generate all possible permutations of an array using recursion.

Test Data* :
*Input the number of elements to store in the array [maximum 5 digits ] :3

Input 3 number of elements in the array :

element - 0 : 1

element - 1 : 2

element - 2 : 3

*:*

Expected Output

Expected Output

The Permutations with a combination of 3 digits are :

123 132 213 231 321 312

Click me to see the solution

**12.** Write a program in C# Sharp to find the LCM and GCD of two numbers using recursion.

Test Data* :
*Input the first number : 10

Input the second number : 15

*:*

Expected Output

Expected Output

The GCD of 10 and 15 = 5

The LCM of 10 and 15 = 30

Click me to see the solution

**13.** Write a program in C# Sharp to convert a decimal number to binary using recursion.

Test Data* :
*Input a decimal number : 66

*:*

Expected Output

Expected Output

The binary equivalent of 66 is : 1000010

Click me to see the solution

**14.** Write a program in C# Sharp to get the reverse of a string using recursion.

Test Data* :
*Input the string : w3resource

*:*

Expected Output

Expected Output

The reverse of the string is : ecruoser3w

Click me to see the solution

**15.** Write a program in C# Sharp to calculate the power of any number using recursion.

Test Data* :
*Input the base value : 5

Input the exponent : 3

*:*

Expected Output

Expected Output

The value of 5 to the power of 3 is : 125

Click me to see the solution

**C# Sharp Code Editor:**

**More to Come !**

**Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.**

**Weekly Trends**- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises

We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook