Lab Assignment 3(Function)
1. Write a program in C to find the square of any number using the
function.
Test Data :
Input any number for square : 20
Expected Output :
The square of 20 is : 400.00
2. Write a program in C to find the sum of the series
1!/1+2!/2+3!/3+4!/4+5!/5 using the function.
Expected Output :
The sum of the series is : 34
3. Write a program in C to find a given element from an array using a function.
Condition:- First check if the given array is sorted or not. If the array is
sorted then call the BinarySearch function otherwise call the linearSearch
function inside the main function.
Function names: 1. isSorted()
2. linearSearch()
3. binarySearch()
4. main()
Expected output:
Enter array size: 5
Enter array elements:
Element 1: 2
Element 2: 4
Element 3: 1
Element 4: 6
Element 5: 9
Enter search element: 6
Linear search result: 3
4. Write a program in C to check Armstrong and Perfect numbers using
the function.
The Armstrong number is a number that is equal to the sum of cubes
of its digits.
A perfect number is a positive integer that is equal to the sum of its
positive divisors, excluding the number itself.
Test Data :
Input any number: 371
Expected Output :
The 371 is an Armstrong number.
The 371 is not a Perfect number.
5. Write a program in C to print the first 10 natural numbers using
recursion.
Expected Output:
The natural numbers are : 1 2 3 4 5 6 7 8 9 10
6. 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 : 10
Expected Output:
The sum of numbers from 1 to 5 : 55
7. Write a program in C to print the Fibonacci Series using recursion.
Expected Output:
Input number of terms for the Series : 10
The Series are :
1 1 2 3 5 8 13 21 34 55
8. Write a program in C to count the digits of a given number using
recursion.
Test Data :
Input a number : 123
Expected Output :
The number of digits in the number is : 3
9. 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
10. 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
11. Write a program in C to check if 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.
12. Write a program in C to find the 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
13. Write a program in C to find the LCM of two numbers using recursion.
Test Data :
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 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 : 10
element - 1 : 20
element - 2 : 30
Input the number to search : 30
Expected Output :
The search number found at index: 2.