[go: up one dir, main page]

0% found this document useful (0 votes)
40 views6 pages

Exe 15 C Recursion

The document provides a series of programming exercises in C that focus on recursion. Each exercise includes a specific task, such as printing natural numbers, calculating sums, generating Fibonacci series, and more, along with expected outputs. The exercises aim to enhance understanding and application of recursion in various programming scenarios.

Uploaded by

nothinga921
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views6 pages

Exe 15 C Recursion

The document provides a series of programming exercises in C that focus on recursion. Each exercise includes a specific task, such as printing natural numbers, calculating sums, generating Fibonacci series, and more, along with expected outputs. The exercises aim to enhance understanding and application of recursion in various programming scenarios.

Uploaded by

nothinga921
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Techno India NJR

C Recursion
1. Write a program in C to print first 50 natural numbers using recursion.
Expected Output :
The natural numbers are : 1 2 3
4 5 6 7 8 9 10 11 12 13
14 15 16 17 18 19 20 21
22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38
39 40 41 42 43 44 45 46 47
48 49 50

2. Write a program in C to calculate the sum of numbers from 1 to n using


recursion.
Test Data :
Input the last number of the range starting from 1 : 5
Expected Output :
The sum of numbers from 1 to 5 :
15

3. Write a program in C to Print Fibonacci Series using recursion.


Test Data :
Input number of terms for the Series (< 20) : 10
Expected Output :
Input number of terms for the Series (< 20) : 10
The Series are :
1 1 2 3 5 8 13 21 34 55

4. Write a program in C to print the array elements using recursion.


Test Data :
Input the number of elements to be stored in the array :6
Input 6 elements in the array :
element - 0 : 2
element - 1 : 4
element - 2 : 6
C LANGUAGE PRACTICE EXERCISE Page 1
Techno India NJR

element - 3 : 8
element - 4 : 10
element - 5 : 12
Expected Output :
The elements in the array are : 2 4 6 8 10 12

5. Write a program in C to count the digits of a given number using recursion.


Test Data :
Input a number : 50
Expected Output :
The number of digits in the number is : 2

6. Write a program in C to find the sum of digits of a number using recursion.


Test Data :
Input any number to find sum of digits: 25
Expected Output :
The Sum of digits of 25 = 7

7. Write a program in C to find GCD of two numbers using recursion.


Test Data :
Input 1st number: 10
Input 2nd number: 50
Expected Output :
The GCD of 10 and 50 is: 10

8. Write a program in C to get the largest element of an array using recursion.


Test Data :
Input the number of elements to be stored in the array :5
Input 5 elements in the array :
element - 0 : 5
element - 1 : 10
element - 2 : 15
element - 3 : 20
C LANGUAGE PRACTICE EXERCISE Page 2
Techno India NJR

element - 4 : 25
Expected Output :
Largest element of an array is: 25

9. Write a program in C to reverse a string using recursion.


Test Data :
Input any string: w3resource
Expected Output :
The reversed string is: ecruoser3w

10. Write a program in C to find the Factorial of a number using recursion.


Test Data :
Input a number : 5
Expected Output :
The Factorial of 5 is : 120

11. Write a program in C to convert a decimal number to binary using


recursion.
Test Data :
Input any decimal number : 66
Expected Output :
The Binary value of decimal no. 66 is : 1000010

12. Write a program in C to check a number is a prime number or not using


recursion.
Test Data :
Input any positive number : 7
Expected Output :
The number 7 is a prime number.

13. Write a program in C to find the LCM of two numbers using recursion.
Test Data :

C LANGUAGE PRACTICE EXERCISE Page 3


Techno India NJR

Input 1st number for LCM : 4


Input 2nd number for LCM : 6
Expected Output :
The LCM of 4 and 6 : 12

14. Write a program in C to print even or odd numbers in given range using
recursion.
Test Data :
Input the range to print starting from 1 : 10
Expected Output :
All even numbers from 1 to 10 are : 2 4 6 8 10
All odd numbers from 1 to 10 are : 1 3 5 7 9

15. Write a program in C to multiply two matrix using recursion.


Test Data :
Input number of rows for the first matrix : 2
Input number of columns for the first matrix : 1
Input number of rows for the second matrix : 1
Input number of columns for the second matrix : 2
Input elements in the first matrix :
element - [0],[0] : 1
element - [1],[0] : 2
Input elements in the second matrix :
element - [0],[0] : 3
element - [0],[1] : 4
Expected Output :
Here is the elements of First matrix :

1
2
Here is the elements of Second matrix :

3 4
The multiplication of two matrix is :

3 4
6 8

C LANGUAGE PRACTICE EXERCISE Page 4


Techno India NJR

16. Write a program in C to Check whether a given String is Palindrome or


not.
Test Data :
Input a word to check for palindrome : mom
Expected Output :
The entered word is a palindrome.

17. Write a program in C to calculate the power of any number using


recursion.
Test Data :
Input the base value : 2
Input the value of power : 6
Expected Output :
The value of 2 to the power of 6 is : 64

18. Write a program in C to find the Hailstone Sequence of a given number


upto 1.
Test Data :
Input any number (positive) to start for Hailstone Sequence : 13
Expected Output :
The hailstone sequence starting at 13 is :
13 40 20 10 5 16 8 4 2 1
The length of the sequence is 10.

19. Write a program in C to copy One string to another using recursion.


Test Data :
Input the string to copy : w3resource
Expected Output :
The string successfully copied.

The first string is : w3resource


The copied string is : w3resource

20. Write a program in C to find the first capital letter in a string using
recursion.
C LANGUAGE PRACTICE EXERCISE Page 5
Techno India NJR

Test Data :
Input a string to including one or more capital letters : testString
Expected Output :
The first capital letter appears in the string testString is
S.

21. Write a program in C for binary search using recursion.


Test Data :
Input the number of elements to store in the array :3
Input 3 numbers of elements in the array in ascending order :
element - 0 : 15
element - 1 : 25
element - 2 : 35
Input the number to search : 35
Expected Output :
The search number found in the array.

C LANGUAGE PRACTICE EXERCISE Page 6

You might also like