You are on page 1of 6

ASSIGNMENT

FUNCTIONS - 1
CLASS XI (Theory)

1. Answer the following:


a) What is a function? Why do we need to use a function?
b) Name the two types of functions.
c) What is the difference between Call by value and Call by reference (with
example)?
d) What is a function declaration? How is a function declaration different from
function definition?
e) What are actual and formal parameters of a function?
f) When a function prototype be omitted?
g) Differentiate between user-defined function and in-built functions.
h) How many values can be returned from a function?
i) Write the header file for the following functions:
isalnum(), rename(), randomize(), frexp()
j) Write a user defined function similar to strcpy ( ) as defined in string.h
k) Write a user defined function similar to strcmp ( ) as defined in string.h
l) Write a user defined function similar to strcat ( ) as defined in string.h
m) Write down the header files, uses and syntax of toupper( ), tolower( )
function.
ASSIGNMENT
FUNCTIONS - 2
CLASS XI (Practical)

1. Write the programs for the following:


a) Define a function power( ) which will take two integer arguments and return
first integer raised to the power second integer. For example, two arguments
are 2 and 3 then the function should return 8.
b) Write a program to read marks of 10 students and then update their marks by
increasing it by 5 marks. Use function for updating the marks.
c) Define a function isprime( ) to check whether a number argument is a prime
or not? Your function should return 1 if the number is prime otherwise 0.

d) Define a function to get an integer number as argument and return the same
but in reverse order. For example, if the argument is 1537, the function should
return 7351.
e) Define a function to get an integer number as argument and return the sum
of the digits of the integer number. For example, if the argument is 1537, the
function should return 16.
f) Define a function to get an integer number as argument and return the sum
of all factors including 1 and excluding number itself.
g) Write a function to receive an int array, its size and a character ‘+’ and ‘-‘. By
default, the character should be ‘+’. For the character ‘+’, the function returns
the sum of positive numbers stored in the array and for the character ‘-’, the
function returns the sum of negative numbers stored in the array.
h) Write a function to sum n natural number starting from a given number.
i) Write a function to find least common divisor of two integers.
j) Write a function to calculate the length of the string and display it.
ASSIGNMENT
FUNCTIONS - 3
CLASS XI (Practical)
1.
Write a function in C++ which accepts a 2D array of integers and its size as
arguments and displays the elements which lie on diagonals.
[Assuming the 2D Array to be a square matrix with odd dimension i.e. 3x3, 5x5, 7x7
etc…]
Example, if the array content is 5 4 3
6 7 8
1 2 9
Output through the function should be:
Diagonal One: 5 7 9 Diagonal Two: 3 7 1

2.
Write a function in C++ which accepts a 2D array of integers and its size as
arguments and displays the elements of Middle Row and the elements of Middle
Column.
[Assuming the 2D Array to be a square matrix with odd dimension i.e., 3X3, 5X5,
7X7 etc.]
Example, if the array content is
354
769
218
Output of the function is:
Middle Row: 7 6 9
Middle Column: 5 6 1

3.
Write a function in C++ which accepts a 2D array of integers and its size as
arguments and displays the Sum of the elements of Middle Row and Sum of the
elements of Middle Column.
[Assuming the 2D Array to be a square matrix with odd dimension i.e., 3X3, 5X5,
7X7 etc.]
Example, if the array content is 354
769
218
Output of the function is:
Sum of the elements of Middle Row: 22
Sum of the elements of Middle Column: 12

4.
Write a function in C++ which accepts a 2D array of integers and its size as
arguments and displays /prints the Product of each Column.
[Assuming the 2D Array to be a square matrix with odd dimension i.e., 3X3, 5X5,
7X7 etc.]
Example, if the array content is 354
769
218
Output of the function is:
Product of 1 Column: 42
Product of 2 Column: 30
Product of 3 Column: 288

5.
Write a function in C++ which accepts a 2D array of integers and its size as
arguments and displays / prints the Product of each Row.
[Assuming the 2D Array to be a square matrix with odd dimension i.e., 3X3, 5X5,
7X7 etc.]
Example, if the array content is 354
769
218
Output of the function is:
Product of 1 Row: 60
Product of 2 Row: 378
Product of 3 Row: 16

6.
Write a function in C++ which accepts a 2D array of integers and its size as
arguments and displays / prints the Sum of each Row.
[Assuming the 2D Array to be a square matrix with odd dimension i.e., 3X3, 5X5,
7X7 etc.]
Example, if the array content is 354
769
218
Output of the function is:
Sum of 1 Row: 12
Sum of 2 Row: 22
Sum of 3 Row: 11

7.
Write a function in C++ which accepts a 2D array of integers and its size as
arguments and displays /prints the Sum of each Column.
[Assuming the 2D Array to be a square matrix with odd dimension i.e., 3X3, 5X5,
7X7 etc.]
Example, if the array content is 354
769
218
Output of the function is:
Sum of 1 Column: 12
Sum of 2 Column: 12
Sum of 3 Column: 21
8.
Write a function in C++ to print the sum of all the values which are either divisible
by 3 or are divisible by 5 present in a two-dimensional array passed as the argument
to the function.

9.
Write a function in C++ which accepts an integer array and its size as arguments and
replaces elements having odd values with thrice its value and elements having even
values with twice its value.
Example: if an array of five elements initially contains the elements as
3, 4, 5, 16, 9
Then, the Output of the function (should rearrange the content of the array) as
9, 8, 15, 32, 27

10.
Write a function in C++ which accepts an integer array and its size as arguments and
replaces elements having even values with its half and elements having odd values
with twice its value.
Example:
If an array of five elements initially contains the elements as 3, 4, 5,16,9
Then, the function should rearrange the contents of the array as
6,2,10,8,18.

11.
Write a function in C++ which accepts an integer array and its size as arguments /
parameters and exchanges the values of first half side elements with the second half
side elements of the array.
Example: If an array of eight elements has initial
content as
8, 10, 1, 3, 17, 90, 13, 60
The function should rearrange the array as
17, 90, 13, 60, 8, 10, 1, 3

12.
Write a function in C++ which accepts an integer array and its size as arguments /
parameters and rearranges the array in reverse. Example, if an array of nine
elements initially contains the elements as
4, 2, 5, 1, 6, 7, 8, 12, 10
Then the function should rearrange the array as
10, 12, 8, 7, 6, 1, 5, 2, 4

13.
Write a function in C++ which accepts a 2D array of integers and its size as
arguments and displays the sum of the elements which lie on diagonals.
[Assuming the 2D Array to be a square matrix with odd dimension i.e. 3x3, 5x5,
7x7 etc…]
Example, if the array content is
5 4 3
6 7 8
1 2 9
Output of the function is:
Sum of Diagonal One: 21 (5 7 9)
Sum of Diagonal Two: 11 (3 7 1)

14.
Write a function in C++ which accepts a 2D array of integers and its size as
arguments and displays the product of the elements which lie on diagonals.
[Assuming the 2D Array to be a square matrix with odd dimension i.e. 3x3, 5x5,
7x7 etc…]
Example, if the array content is
5 4 3
6 7 8
1 2 9
Output of the function is:
Product of Diagonal One: 315 (5 7 9)
Product of Diagonal Two: 21 (3 7 1)

You might also like