You are on page 1of 3

Assignment 4

Q. 4.1 Input 5 numbers from the user and store it in an array. Display the array and find the
sum and average of all the numbers.

Q. 4.2 Input 5 numbers in an array. Now, shift all the elements by one index towards right and
last element to the first index. Print the final modified array.

Q. 4.3 Make a program to print the following array:

1 1
(a) 1 1
1 1

1 1 1
(b) 2 4 8
3 9 27

1 2 3
(c) 1 4 9
1 8 27

0 0 0
(d) 0 1 2
0 2 4

Q. 4.4 Take a list of numbers from the users and sort them in both ascending and descending
order.

Q. 4.5 Store the list of numbers in an array and find the largest and second largest numbers
among them.

Q. 4.6 Store the list of numbers from the user. Find a number using (a) linear search and (b)
binary search.
Q. 4.7 Take the following array from the user. Update the array such that every array element
is the multiplication of previous and next element.
Input:

0 1 2 3 4 5

Output:

0 0 3 8 15 5

Q. 4.8 Write a C++ program to separate even and odd numbers of an array of integers. Put all
odd numbers first and then even numbers.

Q. 4.9 Write a C++ program to separate 0s and 1s from a given array of values having all 0s
and 1s.

Q. 4.10 Write a program to find the transpose of n by m matrix.

Q. 4.11 Take the following two matrices as input and write the C++ program to calculate (a)
A+B, (b) A-B and (c) A*B.

1 6 -4 -2 1 4
A= 2 8 -1 B= 0 9 7
3 9 3 -1 4 -3

Q. 4.12 Write a C++ program to find the determinant and adjoint of the matrix A given above.

Q. 4.13 Write a C++ program to calculate the inverse of a matrix A given in Q. 4.11.

Q. 4.14 Write a code to display the following output:


(a) Square star pattern
*****
*****
*****
*****
*****

(b) Hollow square star pattern

*****
* *
* *
* *
*****
(c) Hollow square star pattern with diagonal

*****
** **
* * *
** **
*****

You might also like