Introduction to Programming
Practice set 6
1. Add Two Numbers Using a Function
Write a function to add two integers and return the sum.
2. Multiply Two Numbers Using a Function
Write a function that multiplies two integers and returns the product.
3. Find the Maximum of Two Numbers
Write a function to find and return the larger of two integers.
4. Swap Two Numbers Using Call by Reference
Write a function to swap two integers using pointers (call by reference).
5. Check if a Number is Even or Odd Using a
Function
Write a function that takes an integer and returns 1 if it is even, and 0 if it is
odd.
6. Print an Array Using a Function
Write a function to print all elements of an integer array.
7. Scan an Array Using a Function
Write a function to input values into an integer array from the user.
1
8. Reverse an Array Using a Function
Write a function to reverse the elements of an integer array.
9. Find the Sum of Array Elements Using a Func-
tion
Write a function that returns the sum of the elements in an integer array.
10. Concatenate Two Strings Using a Function
Write a function to concatenate two strings and store the result in the first
string.
11. Find the Length of a String Using a Function
Write a function that returns the length of a given string.
12. Count Vowels in a String Using a Function
Write a function that counts the number of vowels in a string.
13. Check if a Number is Prime Using a Function
Write a function that checks if a given integer is a prime number.
14. Calculate Factorial Using a Function
Write a function to calculate the factorial of a number.
15. Find the GCD of Two Numbers Using a Func-
tion
Write a function to calculate the greatest common divisor (GCD) of two num-
bers.
16. Find the LCM of Two Numbers Using a Func-
tion
Write a function to calculate the least common multiple (LCM) of two numbers.
2
17. Generate Fibonacci Series Using a Function
Write a function to generate the Fibonacci series up to a certain number of
terms.
18. Count the Number of Digits in a Number
Using a Function
Write a function that returns the number of digits in a given integer.
19. Find the Largest Element in an Array Using
a Function
Write a function to find and return the largest element in an integer array.
20. Check if Two Strings are Equal Using a Func-
tion
Write a function to check if two strings are equal.