You are currently viewing 10th Class Computer Unit-05: Functions

10th Class Computer Unit-05: Functions

10th Class Computer New Course Functions Unit-05

Q.1 Multiple choice questions.

  1. Functions could be built-in or ________________________.

a) admin defined

b) server defined

c) user defined (Correct Answer)

d) Both a and c

2. The functions which are available in C Standard Library are called ________________________.

a) user defined

b) built-in (Correct Answer)

c) recursive

d) repetitive

3. The values passed to a function are called ________________________.

a) bodies

b) return types

c) arrays

d) arguments (Correct Answer)

4. Char cd() {return ‘a’}. In this function “char” is ________________________.

a) body

b) return type (Correct Answer)

c) array

d) arguments

5. The advantages of using functions are ________________________.

a) Readability

b) reusability

c) easy debugging

d) all (Correct Answer)

6. If there are three return statements in the function body, ________________________ of them will be executed.

a) one (Correct Answer)

b) two

c) three

d) first and last

7. Readability helps to ________________________ the code.

a) understand

b) modify

c) debug

d) all (Correct Answer)

8. ________________________ means to transfer the control to another function.

a) Calling (Correct Answer)

b) Defining

c) re-writing

d) Including

Q.2 Define the following.

1) Functions

A function is a block of statements which performs a particular task, e.g. prinf is a function that is used to display anything on computer screen, scanf is another function that is used to take input from the user. Each program has a main function which performs the tasks programmed by the user.

2) Built-in Functions

The functions which are available in C Standard Library are called built-in functions. These functions perform commonly used mathematical calculations, string operations, input/output operations etc.

3) Functions Parameters

Parameters are variables of different data types that are used to receive the values passed to the function as input.

4) Reusability

Function provide reusability of code. It means that whenever we need to use the functionality provided by the function, we just call the function. We do not need to write the same set of statements again and again.

5) Calling a function

Calling a function means to transfer the control to that particular function.

Q.3 Briefly answer the following questions.

1)What is the difference between arguments and parameters? Give an example.

Answer: Difference between arguments and parameters

The values passed to the function are called arguments, whereas variables in the function definition that receive these values are called parameter of the function.

2) Enlist the parts of a function definition.

Answer: Parts of function definition

In C language we have 4 parts while defining a function.

  1. Return_type (function return a value)
  2. Function_name (this the name of a function)
  3. Parameters (a parameter or list of parameters separated by comma)
  4. Function_body (a statement or collection of statements that defines what the function does.)

So the basic structure of function definition well be as below

Return_type FunctionName(Parameter/list of parameters)

{

        Body of the function

}

3) Is it necessary to use compatible data types in function definition and function call? Justify your answer with an example.

Answer: 

Yes, it is necessary to use compatible data types in function definition and function call. For example, if we create a function with two parameters x and y where x is integer type and y is float type and when we call that function in the main function and provide the arguments with x as float type and y as integer type then we get the incorrect result as shown in the following program.

Unit-05 Q3 Example

4) Describe the advantages of using functions.

Answer: Advantages of using functions

Functions provide us several advantages.

  • Reusability: Functions provide reusability of code. It means that whenever we need to use the functionality provided by the function, we just call the function. We do not need to write the same set of statements again and again.
  • Separation of tasks: Function allow us to separate the code of one task from the code of other tasks. If we have a problem in one function, then we do not need to check the whole program for removing the problem. We just need to focus at one single function.
  • Handling the complexity of the problem: If we write the whole program as a single procedure, management of the program becomes difficult. Functions divide the program into smaller units, and thus reduce the complexity of the problem.
  • Readability: Dividing the program into multiple functions, improves the readability of the program.

5) What do you know about the return keyword?

Answer: Return type

Inside the function, return is a keyword that is used to return a value to the calling function.

Q.5 Write down the output of the following code segments.

a. Code

Unit5Q5_p123

Output

b. Code

PTB 10th Unit-05 Q5_b

Output

c. Code

Unit5Q5_c

Output

Unit5Q5_c_answer

d. Code

Unit5Q5d_q

Output

Unit5Q5_d_answer

Programming Exercises

Exercise 1: Write a function int square(int x); to calculate the square of an integer x.

Unit5 Programming Exercise 1

Output

Exercise 2: Write a function int power(int x, int y); to calculate and return xy.

Unit5 Programming Exercise 2

Output

Exercise 3: Write a function to calculate factorial of a number.

Unit 5 Programming Exercise 3 Code

Output

Exercise 4: Write a function which takes values for three angles of a triangle and prints whether the given values make a valid triangle or not. A valid triangle is the one, where the sum of three angles is equal to 180.

Unit 5 Programming Exercise 4 Code

Output

Unit 5 Programming Exercise 4 answer

Exercise 5: Write a function which takes the amount and the interest percentage and return the interest amount.

Unit 5 Programming Exercise Code

Output

Unit 5 Programming Exercise Answer

Exercise 7: Write a function to print the table of a number.

Unit5 Programming Ex7

Output

Unit5 Programming Exercise 6 Answer

Recommended

10th Class Computer New Course User Interaction Unit-02

10th Class Computer New Course User Interaction Unit-02 Q.1 Multiple choice questions. printf is used to print ____________________ type of data. a) int b) float c) char d) All of them (Correct Answer) 2. scanf is a ____________________ in C programming language. a) keyword b) library c) function (Correct Answer) d) none of them 3. […]

9th Computer New Course Networks Unit-03

9th Computer New Course Networks Unit-03 3.1 Choose the correct option. The IPv4 address is made up of ____________________ binary bits. i. 31 ii. 29 iii. 32 (Correct Answer) iv. 30 2. Routing is the process of taking data from one device and sending it to another device in different ____________________. i. Channel ii. Network […]

Buy Best Stationery Products in Pakistan

Piano Ballpoint Pen

Piano Ballpoint Pen

ORO Trimetal Pencil

ORO Trimetal

Dollar Clipper Pen

UHU 10×7 ml Pack of 10 PCs

UHU 10×7 ml Pack of 10 PCs

Glue Stick 8g Pack Of 12 PCs

Glue Stick 8g

Color Pencils Box of 12 PCs

Deer Multi Color Pencils

For more stationery items please visit     :     https://stationerystore.pk