Function Assignments in C — 33 Programs with Solutions
  • Twitter
  • Facebook
  • Snapchat
  • Instagram

Function Assignments in C Language with Explanation and Solutions

📑 Jump to a category:
  • Basic Math Functions (1, 5, 6, 10)
  • Number Checks (2, 4, 7, 8, 11, 14)
  • Series & Tables (3, 9, 12, 13)
  • String Functions (15, 16, 17)
  • Array Functions (18, 19, 20, 21, 22)
  • Matrix Functions (23, 24, 25, 26, 27)
  • Advanced Algorithms (28–33)
  • Previous / Next Topic
📚 What you'll practice across these 33 assignments:
  • Declaring, defining, and calling functions with parameters and return values
  • Pass-by-value semantics and how to return results from functions
  • Writing recursive functions (Fibonacci, GCD, power, subsequences)
  • Passing arrays and matrices to functions
  • Working with strings inside functions (length, reverse, concatenation)
  • Building reusable helper functions for math, number theory, and geometry
  • Implementing classic algorithms — Kadane's, majority element, longest increasing subsequence
  • Decomposing a large problem into smaller, testable functions
  • Understanding scope, visibility, and lifetime of variables
  • Structuring multi-file and modular programs

Functions are the building blocks of every serious C program. They let you break a large, intimidating problem into small, testable pieces — and reuse those pieces across programs. This page collects 33 function assignments, arranged from simple arithmetic to recursive algorithms, string manipulation, array processing, matrix operations, and advanced interview-style problems. Every assignment links to a full tutorial with the program code, sample output, and a line-by-line explanation.

Functions assignments in C programming language with step-by-step explanation, solution, and description.

🔹 Basic Math Functions

Start here — simple arithmetic and geometry functions to get comfortable with parameters and return values.

  • 1. Write a C program to find the sum of two integers using a function.
  • 5. Create a C program to calculate the area of a rectangle using a function.
  • 6. Write a program to convert temperature from Celsius to Fahrenheit using a function.
  • 10. Develop a program to calculate the power of a number using a function.

🔹 Number Checks

Functions that return a yes/no answer or a computed value — prime, even/odd, GCD, LCM, leap year, palindrome.

  • 2. Write a program to check whether a given number is prime or not using a function.
  • 4. Write a program to check whether a number is even or odd using a function.
  • 7. Develop a program to find the GCD (Greatest Common Divisor) of two numbers using a function.
  • 8. Write a program to find the LCM (Least Common Multiple) of two numbers using a function.
  • 11. Write a program to check if a given year is a leap year using a function.
  • 14. Write a program to check if a given number is a palindrome using a function.

🔹 Series & Tables

Generate sequences, swap values, and print tables from within functions.

  • 3. Write a program in C to find the nth term of the Fibonacci series using a function.
  • 9. Create a program to swap two numbers using a function.
  • 12. Create a program to print all prime numbers between two given numbers using a function.
  • 13. Develop a program to generate a multiplication table of a given number using a function.

🔹 String Functions

Pass strings to functions, process them character by character, and return results.

  • 15. Create a program to reverse a string using a function.
  • 16. Develop a program to find the length of a string using a function.
  • 17. Write a program to concatenate two strings using a function.

🔹 Array Functions

Pass arrays to functions, find max/min, sum elements, search, and sort.

  • 18. Create a program to find the maximum element in an array using a function.
  • 19. Develop a program to find the minimum element in an array using a function.
  • 20. Write a program to calculate the sum of elements in an array using a function.
  • 21. Create a program to search for an element in an array using a function.
  • 22. Develop a program to sort elements in an array in ascending order using a function.

🔹 Matrix Functions

2D arrays, matrix operations, and symmetric checks — all implemented with helper functions.

  • 23. Write a program to perform matrix addition using a function.
  • 24. Create a program to calculate the transpose of a matrix using a function.
  • 25. Develop a program to check if a matrix is symmetric using a function.
  • 26. Write a program to perform matrix multiplication using a function.
  • 27. Create a program to find the sum of diagonal elements in a matrix using a function.

🔹 Advanced Algorithms

Interview favorites and algorithm classics implemented as reusable functions.

  • 28. Develop a program to find the largest sum subarray in an array using a function.
  • 29. Write a program to find the longest increasing subsequence in an array using a function.
  • 30. Create a program to find the median of two sorted arrays using a function.
  • 31. Develop a program to find the majority element in an array using a function.
  • 32. Write a program to find the maximum product subarray in an array using a function.
  • 33. Create a program to find the contiguous subarray with the largest sum (Kadane's algorithm) using a function.

How to Get the Most Out of These Assignments

Reading a solution is not the same as writing one. For each assignment, follow this three-step workflow:

  1. Attempt first. Open a blank editor and try to solve the problem using only the assignment description. Even if you get stuck, the act of trying cements the concept.
  2. Compare carefully. Open the solution page and compare your approach to the reference. Look for differences in parameter passing, return type, and edge-case handling.
  3. Re-implement from scratch. Close the solution page and write the program again without looking. This is the step most learners skip — and it's the one that actually builds fluency.

💡 Tip: Always compile with gcc -Wall -Wextra -std=c11 -g. The -Wall and -Wextra flags warn you about missing prototypes, unused parameters, and implicit conversions — all common mistakes when writing your first functions.

❓ Function Viva Questions & Quick Answers

Q1. What is the difference between a function declaration and a function definition?

A declaration (prototype) tells the compiler the function's name, return type, and parameter types. A definition provides the actual body of the function. You can declare a function many times, but define it only once.

Q2. What does "pass by value" mean in C?

When you pass an argument to a function, C copies its value into the parameter. Changes made to the parameter inside the function do not affect the original variable in the caller.

Q3. How can a function modify a variable in the caller?

By accepting a pointer to the variable. Dereferencing the pointer inside the function allows you to modify the original value. This is commonly called "pass by reference" — implemented in C using pointers.

Q4. What is recursion, and when should I use it?

Recursion is a function that calls itself. Use it when a problem naturally breaks into smaller instances of the same problem — e.g., Fibonacci, GCD, tree traversal. Always include a base case, or the recursion will run forever.

Q5. Can a function return an array?

Not directly — C functions cannot return arrays. You can return a pointer to an array (which must not be a local variable), or pass an output array as a parameter and fill it inside the function.

Q6. What is the difference between a function prototype and a function header?

The prototype ends with a semicolon and contains no body — e.g., int add(int, int);. The header is the first line of the definition — e.g., int add(int a, int b) — and is followed by the function body.

📖 Related Tutorials

  • Introduction To Functions In C
  • Need For User-Defined Functions
  • Multiple Function Program
  • Modular Programming
  • Elements Of User Defined Function
  • Function Definition
  • Function Declaration
  • Types Of Functions
  • Nesting Of Functions
  • Recursion
  • Passing Arrays To Functions
  • Scope, Visibility And Lifetime Of Variables
  • Function FAQ
  • Function Multiple-Choice Questions

Previous Topic: -->> Array Assignments in C   ||   Next topic: -->> Structure Assignments in C


C Language

  • Home
  • Why C Language
  • History of C Language
  • Applications of C Language
  • Introduction To C
    • What is Program?
    • Structure of C Program
    • Working Of C Program
    • CHARACTER SET
    • VARIABLES AND IDENTIFIERS
    • BUILT-IN DATA TYPES
    • OPERATORS AND EXPRESSIONS
    • CONSTANTS AND LITERALS
    • SIMPLE ASSIGNMENT STATEMENT
    • BASIC INPUT/OUTPUT STATEMENT
    • SIMPLE 'C' PROGRAMS
    • Assignments
  • Operators in C Programming
    • Arithmetic Operators
    • Assignment Operators
    • Increment and Decrement Operators
    • Relational Operators
    • Logical Operators
    • Bitwise Operators
    • Other Operators
    • Assignments
  • CONDITIONAL STATEMENTS
    • DECISION MAKING WITHIN A PROGRAM
    • CONDITIONS
    • IF STATEMENT
    • IF-ELSE STATEMENT
    • IF-ELSE LADDER
    • NESTED IF-ELSE
    • SWITCH CASE
    • Assignments
  • LOOPS STATEMENTS
    • Introduction to Loops
    • GO TO Statement
    • Do while Loop
    • While Loop
    • Nested While Loop
    • Difference Between While and Do while
    • Difference Between Goto and loop
    • while loop assignments
    • C FOR Loop
    • C For loop examples
    • Nested for loop
    • Nested for loop examples
    • Infinite while Loops
    • Infinite for Loops
    • Continue in Loops
    • break in Loops
    • difference while do..while & for
    • Assignments
  • Arrays
    • One Dimensional Array
    • Declaring 1D Arrays
    • Initilization of 1D arrays
    • Accessing element of one 1D Array
    • Read and Display 1D Arrays
    • Two Dimensional Arrays
    • Declare 2D Arrays
    • Read and Display 2D Arrays
    • Assignments/Examples
  • Functions
    • Introduction
    • Need For User-Defined Function
    • Multiple Function Program
    • Modular Programming
    • Elements Of User Defined Function
    • Function Definition
    • Function Declaration
    • Types of functions
    • Nesting of Function
    • Recursion
    • Passing Array To Functions
    • Scope,Visibility and Lifetime of Variables
    • Assignments
  • Structure
    • Introduction
    • Array vs Structure
    • Defining Structure
    • Declaring Structure Variables
    • Type Defined Structure
    • Accessing Structure Members
    • Structure Initilization
    • Copying & Comparing Structure Variables
    • Array of Structure
    • Arrays Within Structure
    • Structures Within Structures
    • Structures and Functions
    • Structure Examples/Assignments
  • Union
    • Define Union
    • Create and use Union
    • Difference Between Structure and Union
    • Union Examples
    • Union FAQ
  • Pointers
    • What Are Pointers In C?
    • How Do We Use Pointers In C?
    • Declaration Of A Pointer
    • The Initialization Of A Pointer
    • Syntax Of Pointer Initialization
    • Use Of Pointers In C
    • The Pointer To An Array
    • The Pointer To A Function
    • The Pointer To A Structure
    • Types Of Pointers
    • The Null Pointer
    • The Void Pointer
    • The Wild Pointer
    • The Near Pointer
    • The Huge Pointer
    • The far Pointer
    • dangling pointer
    • Accessing Pointers- Indirectly And Directly
    • Pros Of Using Pointers In C
    • Cons Of Pointers In C
    • Applications Of Pointers In C
    • The & Address Of Operator In C
    • How To Read The Complex Pointers In C?
    • Practice Problems On Pointers
  • File Processiong
    • File Handling In C
    • Types Of Files In C
    • Operations Done In File Handling
    • File Examples
    • Binary Files
    • count words,lines in a file
    • Copy files
    • Update File
    • count vowels in a file
  • Preprocessor
    • Macro substitution division
    • File Inclusion
    • Conditional Compilation
    • Other directives
    • Examples
  • Dynamic Memory Allocation
    • malloc
    • calloc
    • free
    • realloc
    • Examples
  • Storage Classes
  • Graphics
  • Frequently Asked Interview Questions (FAQ)
    • Introduction To C FAQ
    • Operators FAQ
    • Conditional Statements FAQ
    • Loops FAQ
    • Arrays FAQ
    • Function FAQ
    • Structure FAQ
    • Pointers FAQ
    • Files FAQ
    • Storage classes FAQ
    • Dynamic Memory FAQ
  • Programs/Assignments
    • Introduction To C
    • Operators
    • Conditional Statements
    • Loops
    • Arrays
    • Function
    • Structure
    • Pointers
    • Files
    • Storage classes
    • Dynamic Memory
  • Case Studies
  • Multiple Choice Questions
    • Introduction To C MCQ
    • Operators MCQ
    • Conditional Statements MCQ
    • Loops MCQ
    • Arrays MCQ
    • Function MCQ
    • Structure MCQ
    • Pointers MCQ
    • Files MCQ
    • Storage classes MCQ
    • Dynamic Memory MCQ
    • More MCQ

Get in touch

  • tech2dsm@gmail.com

© Sankalan Data Tech. All rights reserved.