Looking for accurate SEBA Class 10 Computer Science Chapter 7 (Functions in C) textual solutions for the 2026–27 academic year? Access step-by-step textbook exercise answers, function prototype definitions, user-defined vs library functions, return statement explanations, and full C programming solutions designed to help you score top marks in your HSLC board exams.
1. What is a global variable in C? Why do we need such a variable?
Answer: A global variable is a variable declared outside of any function, making it accessible to all functions in a program. It has a global scope, meaning it keeps its value as long as the program is running. Any function in the program can use or modify it.
2. Write the syntax of a function declaration. The name of the function is calculateAge(). The function accepts the current year and birth year of a person. The function returns the age of the person.
Answer: The function calculateAge() takes two inputs: the current year and the birth year of a person. It calculates and returns the person’s age.
Function Declaration:int calculateAge(int current_year, int birth_year);
3. Write the code segment for the function definition of the above function calculateAge().
Answer:The code for the function calculateAge(). It takes the current year and birth year as inputs, calculates the age, and returns it:
int calculateAge(int current_year, int birth_year)
{
int age;
age = current_year – birth_year;
return age;
}
4. What are different types of functions in C ? Differentiate among them.
Answer:In C programming, functions are broadly classified into two types:
- Standard Library (Built-in) Functions: These are predefined functions stored in standard C libraries (header files). Programmers can use them directly without writing their implementation code (e.g., printf(), scanf(), sqrt()).
- User-Defined Functions: These are custom functions created by programmers to meet specific requirements and perform particular tasks in a program (e.g., sum(), calculateArea()).
| Feature | Standard Library Functions | User-Defined Functions |
| Definition | Predefined functions included in the C software package. | Custom functions created and written by the programmer. |
| Availability | Ready to use directly by including appropriate header files. | Must be declared, defined, and called by the programmer. |
| Functionality | Fixed behavior; cannot be altered by the programmer. | Flexible; behavior can be customized according to program requirements. |
| Examples | printf(), scanf(), sqrt(), pow() | main(), add(), factorial(), display() |
5. Differentiate between caller and callee functions. write a small C progarm and identify the caller and callee function in it.
Answer:
| Caller Function | Callee Function |
| The function that invokes or calls another function during program execution is known as the caller function. | The function that is executed upon being called to perform a specific task is known as the callee function. |
| It passes arguments or actual parameters to the function being called. | It receives the formal parameters, executes its internal body of code, and returns the output back to the caller. |
| Control remains with this function until it transfers execution flow to the target function. | Control enters this function when it is called and exits back to the caller upon completion or hitting a return statement. |
| Example: In a C program, main() acts as the caller function when it calls add(x, y). | Example: In a C program, add(int a, int b) acts as the callee function when executed by main(). |
Example in C:
`#include
int add(int a, int b)
{
return a + b;
}
int main() {
int x = 5, y = 3;
int result = add(x, y); // Call the add function
printf(“The result of adding %d and %d is %d\n”, x, y, result);
return 0;
}
Explanation:
main is the caller because it calls the add function.
add is the callee because it performs the addition and returns the result.
Functions in C Class 10 SEBA Textual Exercise Solutions
6. When do we call a function user-defined? Is printf() a user-defined function? Justify.
Answer: A user-defined function is created by the programmer to organize the code and perform specific tasks. Once defined, these functions can be called like built-in functions.
No, printf() is not a user-defined function. It is a built-in function, also known as a library function.
7. Can we have two functions with the same name but with different numbers of parameters in a single C program? Write a simple C program to justify your answer.
Answer: No, in C programming, we cannot have two functions with the same name, even if they have different numbers of parameters. This will cause a conflict during compilation.
Example Code:
#include
// Function with one parameter
void printMessage(char* message)
{
printf(“%s\n”, message);
}
// Attempting another function with the same name but no parameters
void printMessage()
{
printf(“No message provided.\n”);
}
int main()
{
char message[] = “Hello, World!”;
printMessage(message); // Call the first function
return 0;
}
“`
Output:
When you try to compile this program, you’ll see an error like:error: conflicting types for 'printMessage'
8. What are different components of a function? Show with a complete C program.
Answer: A function in C has three main parts:
- Function Declaration: Includes the function’s name, return type, and parameters (if any).
- Function Definition: Contains the code or statements that execute when the function is called.
- Function Call: Invokes the function from another part of the program.
Example Code:
#include
// Function Declaration
int add(int a, int b);
// Function Definition
int add(int a, int b)
{
int sum = a + b;
return sum;
}
int main()
{
// Function Call
int x = 5, y = 3;
int result = add(x, y); // Call the add function
printf(“The result of adding %d and %d is %d\n”, x, y, result);
return 0;
}
9. Define recursive function. Can we use a recursive function to solve all kinds of problems?
Answer: A recursive function is a function that calls itself repeatedly, either directly or indirectly, until a specific condition or task is completed.
While recursive functions are powerful and can solve many types of problems, they are not always the best or most efficient choice for all problems. Whether recursion is suitable depends on the problem’s nature and the task’s requirements.
Class 10 Computer Science Chapter 7 Question Answer SEBA 2026-27
10. Consider the below code and list all the syntax errors.
#include<stdio,h>
int fun ( int x )
{
if ( x %2 == 0 )
return 1;
else
return 0;
}
int main()
{
int number;
printf (“\n Enter the number: ” );
scanf ( “%d”, &number );
int x = fun ( );
return 0;
}
Answer: Original Code Errors:
#include<stdio.h>
int fun ( int x )
{
if ( x %2 == 0 )
return 1;
else
return 0;
}
int main()
{
int number;
printf (“\n Enter the number: ” );
scanf ( “%d”, &number );
int x = fun ( );
return 0;
}
- The
printfandscanffunctions use incorrect curly quotes (“and”) instead of standard double quotes ("). - The
funfunction is called without an argument, but it is defined to take one integer parameter. The correct call should pass an integer value (e.g.,fun(number)).
Corrected Code:
#include
int fun(int x) {
if (x % 2 == 0)
return 1;
else
return 0;
}
int main() {
int number;
printf(“\nEnter the number: “);
scanf(“%d”, &number);
int x = fun(number); // Pass the ‘number’ as an argument
return 0;
}
11. Consider the code segment below and find out the output if the user enters 5 from
the keyboard when asked for.
#include<stdio.h>
int fun ( int x )
{
if ( x %2 == 0 )
return 1;
else
return 0;
}
int main()
{
int number;
printf (“\n Enter the number: ” );
scanf ( “%d”, &number );
int x = fun ( number);
printf(“%d”, x);
return 0;
}
Answer: `#include<stdio.h>
int fun ( int x )
{
if ( x %2 == 0 )
return 1;
else
return 0;
}
int main()
{
int number;
printf (“\n Enter the number: ” );
scanf ( “%d”, &number );
int x = fun ( number);
printf(“%d”, x);
return 0;
}
In the provided code, when the user enters 5, the program will check whether the number is even or odd using the function fun. Since 5 is an odd number, the function will return 0.
SEBA Class 10 Computer Science Chapter 7 Programs
12. Write a C program and define a function square() that accepts a number as the parameter and returns the square of that number as output.
Answer: The program defines a function square() that takes a number as input and returns its square. Here’s how it works:
- The user enters a number.
- The
square()function calculates the square of that number. - The result is then displayed on the screen.
#include
// Function to calculate the square of a number
int square(int num)
{
return num * num;
}
int main()
{
int number, result;
// Input from the user
printf(“Enter a number: “);
scanf(“%d”, &number);
// Calculate the square using the 'square' function
result = square(number);
// Display the result
printf("The square of %d is %d\n", number, result);
return 0;
}
Output:
Enter a number: 5
The square of 5 is 25
13. Write a C program and define a function search () that searches an element in an array and returns the index of the element.
Answer: This program defines a function search() that searches for an element in an array and returns the index where the element is found. If the element is not found, it returns -1.
- The user is prompted to enter the element to search for.
- The
search()function checks each element in the array. If it finds the element, it returns the index. - The result is displayed: either the index of the element or a message indicating the element is not found.
#include
// Function to search for an element in an array
int search(int a[], int size, int target)
{
for (int i = 0; i < size; i++)
{
if (array[i] == target)
{
return i; // Element found, return its index
}
else
return -1; // Element not found, return -1
}
}
int main()
{
int a[] = {10, 20, 30, 40, 50, 60, 70};
int size = sizeof(a);
int target, result;
printf("Enter the element to search for: ");
scanf("%d", &target);
result = search(array, size, target);
if (result != -1)
{
printf("Element %d found at index %d\n", target, result);
}
else
{
printf(“Element %d not found in the array\n”, target);
}
return 0;
}
Output:
Enter the element to search for: 30
Element 30 found at index 2
14. Write a C program and define a recursive function to find the summation of first N natural numbers.
Answer: This program defines a recursive function sumOfNaturals() that calculates the sum of the first N natural numbers.
- The function checks if
nis1. If it is, it returns1as the sum. - If
nis greater than1, the function calls itself withn-1and addsnto the result. - The sum is calculated recursively and then displayed.
#include
// Recursive function to find the summation of first N natural numbers
int sum(int n)
{
if (n == 1)
{
return 1;
} else
{
return n + sum(n – 1);
}
}
int main()
{
int N, result;
printf(“Enter a positive integer N: “);
scanf(“%d”, &N);
if (N < 1)
{
printf("N must be a positive integer.\n");
}
else
{
result = sum(N);
printf("The sum of the first %d natural numbers is %d.\n", N, result);
}
return 0;
}
Output:
Enter a positive integer N: 5
The sum of the first 5 natural numbers is 15.
Explanation:
The function sumOfNaturals() adds all natural numbers from 1 to N using recursion. For example, if N = 5, it calculates 5 + 4 + 3 + 2 + 1.
SEBA Class 10 Computer Science Chapter 7 Solutions
15. Write a C program and define a function add() that accepts three integers. These integers indicate indices of an integer array. The function returns the summation of the elements stored in those indices.
Answer: This program defines a function add() that accepts three indices, sums the elements at those positions in the array, and returns the result.
- The array contains the elements
{7, 8, 8, 0, 0, 9}. - The function
add()takes three indices as input and adds the values at those positions. - The result is printed as the sum of the elements at the specified indices.
#include
// Function to calculate the sum of elements at specified indices
int add(int a[], int i1, int i2, int i3)
{
return a[i1] + a[i2] + a[i3];
}
int main()
{
int a[] = {7, 8, 8, 0, 0, 9}; // Array of integers
// Indices of the elements to sum
int i1 = 0, i2 = 2, i3 = 5;
// Call the add function and store the result
int result = add(a, i1, i2, i3);
// Display the result
printf("The sum of elements at indices %d, %d, and %d is %d\n", i1, i2, i3, result);
return 0;
}
Explanation:
The elements at indices 0, 2, and 5 are 7, 8, and 9, respectively. Their sum is 7 + 8 + 9 = 24.
`#CProgramming #ArrayOperations
💻 Updated Solutions Notice: This page features complete, step-by-step SEBA Class 10 Computer Science Chapter 7 (Functions in C) Textual Exercise Solutions updated for the 2026–27 academic session. All function syntax rules, parameter passing logic, and C programming codes strictly follow the latest revised Assam Board (SEBA) textbook.
💡 Ace Your HSLC Computer Science Exam:
- Have a doubt about main function return types, actual vs formal parameters, or function declarations in C? Drop your query in the comments section below!
- Save and bookmark this solution guide for quick reference before your unit tests, half-yearly, and pre-board examinations.
- Share this link with your classmates and WhatsApp study groups to help them master C programming concepts!