C Programming Function Problems Corrected
C Programming Function Problems Corrected
Easy:
Write a function sum(int a, int b) that takes two integers and returns their sum. Call this function from main and print the
result.
2. Factorial of a Number
Write a function int factorial(int n) that returns the factorial of a given number n. Test the function by printing the factorial
of numbers 1 to 5.
Write a function int max(int a, int b) that returns the maximum of two numbers. Use this function to find the maximum of
Write a function int isEven(int n) that returns 1 if a number is even and 0 if it is odd. Use this function in main to check if
Intermediate:
Write a function int isPrime(int n) that returns 1 if a number is prime and 0 if it is not. Use this function to check whether
Write a function int gcd(int a, int b) that returns the greatest common divisor of two numbers. Test this function with
7. Array Sum
Write a function int sumArray(int arr[], int size) that takes an array and its size as arguments and returns the sum of its
8. Fibonacci Sequence
Write a function int fibonacci(int n) that returns the nth Fibonacci number. Use this function to print the first 10 Fibonacci
numbers.
Write a function void swap(int *a, int *b) that swaps the values of two integers using pointers. Test this function by
Advanced:
Write a recursive function int power(int base, int exp) that returns the value of base raised to the power exp. Use this
Write a function int isPalindrome(int num) that checks if a given number is a palindrome (reads the same forwards and
Write a function void sortArray(int arr[], int size) that sorts an array of integers in ascending order using the Bubble Sort
Write a function void multiplyMatrices(int mat1[3][3], int mat2[3][3], int res[3][3]) that multiplies two 3x3 matrices and
Write a function int binarySearch(int arr[], int size, int target) that implements the binary search algorithm to find the
position of a target element in a sorted array. If the element is not found, return -1.
Create a menu-driven program where the user can choose different operations (like sum, difference, product, quotient,
GCD, etc.) to be performed using functions. Implement each operation as a separate function.
C Programming Function Problems
Expert:
Write a function void reverseString(char *str) that reverses a string in place using pointers. Test the function with various
strings.
Write a function void solveNQueens(int n) that finds all possible solutions to the N-Queens problem using backtracking
Write a recursive function void towerOfHanoi(int n, char from_rod, char to_rod, char aux_rod) to solve the Tower of
Hanoi puzzle. Print the sequence of moves needed to solve the puzzle.
Write a function void mergeSort(int arr[], int l, int r) that implements the Merge Sort algorithm to sort an array of integers.
Write a function int solveSudoku(int grid[9][9]) that solves a given Sudoku puzzle using backtracking and prints the
solution.
C Programming Function Problems
Bonus Challenge:
Write a function int evaluateExpression(char *expression) that evaluates a mathematical expression given as a string
(e.g., "3 + 5 * (2 - 4)") and returns the result. Implement support for basic arithmetic operations and parentheses.