0% found this document useful (0 votes)
24 views

CPP Assignment 2

The document contains 5 questions about C++ programming. Question 1 asks to write a function to find all pairs of elements in an array whose sum equals a given number. Question 2 asks to merge two sorted arrays while maintaining sorted order. Question 3 asks to declare a square matrix, accept user input for size, display the original matrix, rotate it 90 degrees clockwise, and find the sum of corner elements. Question 4 asks to sum corresponding elements of two arrays into a third array. Question 5 asks to update all elements of a 2D array except the secondary diagonal elements.

Uploaded by

SHAKSHAT BOT
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

CPP Assignment 2

The document contains 5 questions about C++ programming. Question 1 asks to write a function to find all pairs of elements in an array whose sum equals a given number. Question 2 asks to merge two sorted arrays while maintaining sorted order. Question 3 asks to declare a square matrix, accept user input for size, display the original matrix, rotate it 90 degrees clockwise, and find the sum of corner elements. Question 4 asks to sum corresponding elements of two arrays into a third array. Question 5 asks to update all elements of a 2D array except the secondary diagonal elements.

Uploaded by

SHAKSHAT BOT
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment-2

Q1.Write a C++ program to a function.

void arrayFunc(int num[],int size , int sum)  To find all pairs of elements in an

Array whose sum is equal to a given number :

Sample

Array numbers= [4, 6, 5, -10, 8, 5, 20], size= 7 , sum=10

Output :

Pairs of elements whose sum is 10 are :


4 + 6 = 10
5 + 5 = 10
-10 + 20 = 10

Q2. Write a C++ program to a function


void arraySort(int A[], int p, int B[], int q)  Given two sorted arrays A and B of size
p and q, define function arraySort() to merge elements of A with B by maintaining the
sorted order i.e. fill A with first p smallest elements and fill B with remaining elements.

Example:
Input :
int[] A = { 1, 5, 6, 7, 8, 10 }
int[] B = { 2, 4, 9 }
Output:
Sorted Arrays:
A: [1, 2, 4, 5, 6, 7]
B: [8, 9, 10]
Q3.Write a program to declare a square matrix A[ ][ ] of order MxM where ‘M’ is the number of
rows and the number of columns, such that M must be greater than 2 and less than 10. Accept the
value of M as user input. Display an appropriate message for an invalid input. Allow the user to
input integers into this matrix. Perform the following tasks:
(a) Display the original matrix.
(b) Rotate the matrix 90° clockwise as shown below:
(c) Find the sum of the elements of the four corners of the matrix.
Test your program for the following data and some random data:
Example 1
INPUT :
M = 3

 OUTPUT :
ORIGINAL MATRIX

MATRIX AFTER ROTATION

Sum of the corner elements = 20

Q4.Accept numbers in array A[10] & create another array


B[5]. The array B first location fills with sum of first &
second location of array A. The array B second location
fills with sum of third & forth location of array A. Similarly

fill all the position of array B & display it.


Q5. Write a C++ function to update all the elements of a
given 2D array except the secondary diagonal elements (the
diagonal from bottom-left to top-right). Height and width of
the matrix are also provided as arguments.

You might also like