# C# Sharp programming Exercises, Practice, Solution: Recursion

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

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

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. Go to the editor

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 first n natural numbers using recursion. Go to the editor

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. Go to the editor

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. Go to the editor

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. Go to the editor

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. Go to the editor

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 Palindrome or not using recursion. Go to the editor

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. Go to the editor

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 n numbers of series using recursion. Go to the editor

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. Go to the editor

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. Go to the editor

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. Go to the editor

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. Go to the editor

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. Go to the editor

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.**

**New Content published on w3resource:**- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- React - JavaScript Library
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework