SEBA Class 10 Computer Science Chapter 7 Functions In C

Join Roy Library Telegram Groups

Hello Viewers Today’s We are going to Share With You, The Complete Syllabus of SEBA Class 10 Computer Science Chapter 7 Functions In C Solutions in English in This Page. Are you a Student of (Secondary Education Board of Assam). SEBA Class 10 Computer Science Chapter 7 Functions In C Notes. Which you Can Download PDF SEBA Class 10 Computer Science Chapter 7 Functions In C Question Answer for free using direct Download Link Given Below in This Post.

SEBA Class 10 Computer Science Chapter 7 Functions In C

We have Shared in This Post, SEBA Class 10 Computer Science Chapter 7 Functions In C Textbook PDF Download for Free with you. SEBA Class 10 Computer Science Chapter 7 Functions In C Solutions PDF. I Hope, you Liked The information About The SEBA Class 10 Computer Science Chapter 7 Functions In C Book PDF. If you liked Class 10 Computer Science Notes Then Please Do Share this Post With your Friends as Well.

Functions In C

TEXTUAL QUESTIONS AND ANSWERS

EXERCISE

1. What is a global variable in C? Why do we need such a variable?

Ans. The variables that are declared outside the given function are known as global variables. It has a global scope means it holds its value throughout the lifetime of the program. Hence, it can be accessed throughout the program by any function defined within the program.

2. Write the syntax of a function declaration. 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.

Ans. Function declaration:

int calculate Age(int current_year, int birth_year);

3. Write the code segment for the function definition of the above function calculate Age().

Ans. Code segment:

int calculateAge(int current_year, int birth_year)

{

int age;

age = current_year – birth_year,

return age;

}

4. What are the different types of functions in C? Differentiate between them.

Ans. There are two types of functions:

  • Library functions
  • User – defined functions

Library functions are built-in functions which are defined inside C library whereas, user-defined functions are declared and defined by the programmer based on their needs.

5. Differentiate between caller and callee functions. Write a small C program and identify the caller and callee function in it.

Ans. A caller is a function that calls another function; a callee is a function that was called.

Example:

#include <stdio.h>int add(int, int);int add(x, y){return (x+y);}int main(){int num, a, b, sum;printf(“Enter the numbers to be added “);scanf(“%d%d”, &a,&b);sum = add(a,b);printf(“Sum=%d”, sum);return 0;}

In the above program, main() is another function and it is calling a function add(). Thus main() can be called as a caller function and add() can be called as a callee function.

6. When do we call a function user-defined? Is printf() a user-defined function? Justify.

Ans. User-defined functions allow programmers to create their own routines and procedures that the computer can follow; it is the basic building block of any program and also very important for modularity and code reuse since a programmer could create a user-defined function which does a specific process and simply call it.

No, printf() is not a user-defined function. It is a built-in-function which is also called 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.

Ans. In C program, we cannot have two functions with the same name. However, in C++ it’s entirely possible as long as the function signature is different, i.e. two functions having the same name but different set of parameters.

8. Write the different components of a function? Show with a complete C program.

Ans. There are three parts of a function in C.

(a) Function declaration – The function must be declared first before its use.

(b) Function call – This statement is responsible for the execution of a function.

(c) Function definition – This portion of a function contains the actual statements that are executed when the function is called.

Example:

9. Define recursive function. Can we use a recursive function to solve all kinds of problems?

Ans. Recursive Function is a function that repeats or uses its own previous term to calculate subsequent terms and thus forms a sequence of terms.

Recursion makes solving problems easier by breaking them into smaller sub problems thereby making it easier to understand the problem. As such, not all problems can be broken down into smaller sub problems so that they could be solved recursively.

10. Consider the below code and list all the syntax Consider the below code and list all the syntax errors.

#include<stdio.h>int fun (int x){if (x % 2 == 0)return 1;elsereturn 0;}int main (){int number,printf(“\n Enter the number: “);scanf(“%d”, &number);int x = fun ();return 0;}

Solution:

#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 (); Error – few arguments

No printf() function

return 0;

}

Rewrite:

#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;

}

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;

}

Ans. Output will be 0

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.

Solution:

Code:

#include<stdio.h>int square (int x){int sq = x * x;return sq;}int main(){int number,printf(“\nEnter the number: “);scanf(“%d”, &number);int x = square (number);printf(“%d”,x);return 0;}

Output:

S.L No.CONTENTS
Chapter 1Introduction To Computer Network
Chapter 2Html5 And Css3
Chapter 3Database Part – II Mysql
Chapter 4Introduction To Loops
Chapter 5Nested Loops In C
Chapter 6Arrays In C
Chapter 7Functions In C
Chapter 8Pointers In C
Chapter 9Structure In C
Chapter 10An Introduction To Object Oriented Programming
Chapter 11Case Studies

13. Write a C program and define a function search () that searches an element in an array and returns the index of the element.

Solution:

Code:

#include<stdio.h>int arr[7];int i;int search (int x){int index,for(i=0;i<7;i++){if(arr[i]== x)index = i;}return index;}int main(){int s;printf(“\nEnter the array elements:”);for(i=0; i<7; i++){scanf(“%d”, &arr[i]);}printf(“\n Enter the number to be searched in the array: “);scanf(“%d”,&s);int x = search (s);printf(“\n The index of the searched number is %d “, x);return 0;}

Output:

14. Write a C program and define a recursive function to find the summation of first N natural numbers.

Solution:

Code:

#include <stdio.h>int addNumbers(int n){if (n != 0)return n + addNumbers(n-1);elsereturn n;}int main() {int num;printf(“Enter the number: “);scanf(“%d”, &num);printf(“Sum=%d”, addNumbers(num));return 0;}

Output:

15. Write a C program and define a function add () that accept three integers. These integers indicate indices of an integer array. The function returns the summation of the elements stored in those indices.

7 8 8 0 0 9

For example, if we call the function add (0, 2, 5), the function will return 24. The output is formed by 7+ 8 + 9 because elements at indices 0, 2 and 5 are 7, 8 and 9 respectively.

Solution:

Code:

#include <stdio.h>int arr[7], i;int add(int x, int y, int z){int sum;for(i=0; i<7; i++){sum = arr[x] + arr[y] + arr[z];}return sum;}int main(){int num, a, b, c, d;printf(“Enter the numbers of arrays: “);for(i=0; i<7; i++){scanf(“%d”, &arr[i]);}printf(“\nEnter the three indices whose elements to be added in array: “);scanf(“%d%d %d”, &a, &b, &c);d = add(a,b,c);printf(“Sum = %d”, d);return 0;}

Output:

ADDITIONAL QUESTIONS AND ANSWERS

1. What are functions in C?

Ans. A function is a group of tasks used to execute the predefined operations and returns a value. A large program can be divided into small blocks of code that help to understand the logic, debug, and modified it.

2. Where are global variables declared in C?

Ans. Global variables are generally written before main() function.

3. What are local and global variables?

Ans. Global variables are those which are not defined inside any function and have a global scope whereas local variables are those which are defined inside a function and its scope is limited to that function only.

4. What is recursion and recursive function in C?

Ans. In C, when a function calls a copy of itself then the process is known as recursion. To put it short, when a function calls itself then this technique is known as recursion and the function is known as a recursive function.

5. What is user-defined functions?

Ans. User-defined functions are declared and defined by the programmer based on their needs.

6. What is library/built-in functions?

Ans. A library function is predefined functions, and its tasks are also defined in the C header files. So, it does not require writing the code of the particular function; instead, it can be called directly in a program whenever it is required.

Example: printf(), scanf() etc., are the predefined function in the C library, and the meaning of these functions cannot be changed.

7. What is function declaration?

Ans. A function declaration defines the name and return type of a function in a program. Before using the function, we need to declare it outside of a main() function in a program.

8. What is function call?

Ans. A function call is an important part of the C programming language. It is called inside a program whenever it is required to call a function. It is only called by its name in the main() function of a program. We can pass the parameters to a function calling in the main() function.

9. What is function definition?

Ans. It defines the actual body of a function inside a program for executing their tasks in C.

10. Define the following terms:

(a) Return Data_Type: It defines the return data type of a value in the function. The return data type can be integer, float, character, etc.

(b) Function Name: It defines the actual name of a function that contains some parameters.

(c) Parameters/ Arguments: It is a parameter that passed inside the function name of a program. Parameters can be any type, order, and the number of parameters.

(d) Function Body: It is the collection of the statements to be executed for performing the specific tasks in a function.

11. Is printf() a function call?

Ans. The printf() is a library function to send formatted output to the screen. The function prints the string inside quotations. To use printf() in our program, we need to include stdio.h.

12. What is void main() in C?

Ans. The void main() indicates that the main() function will not return any value, but the int main() indicates that the main() can return integer type data. When our program is simple, and it is not going to terminate before reaching the last line of the code, or the code is error free, then we can use the void main().

13. What does int main() mean in C?

Ans. An int is a keyword that references an integer data type. An int data type used with the main() function that indicates the function should return an integer value. When we use an int main() function, it is compulsory to write return 0; statement at the end of the main() function.

14. What is argument in C?

Ans. An argument is referred to the values that are passed within a function when the function is called. These values are generally the source of the function that require the arguments during the process of execution.

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

Ans. A declaration occurs once, but a definition may occur many times.

16. Write a C program to find factorial of a number using recursive function.

Solution:

Code:

#include<stdio.h>int fact(int n){if (n>=1)return n*fact(n-1);elsereturn 1;}int main(){int n;printf(“Enter a number: “);scanf(“%d”,&n);printf(“Factorial of %d = %d “, n, fact(n));return 0;}

Output:

Leave a Reply

error: Content is protected !!
Scroll to Top