0% found this document useful (0 votes)
88 views4 pages

Arrays Last Year Questions ONLY

1. Write a function to add corresponding elements of two equi-sized arrays and store the results in a third array 2. Write a function to add even positions of an array with the next element and increment odd positions by 10 3. Write a function to calculate the sum of the middle column elements of a 2D array 4. Write a function to calculate the sum of the middle row elements of a 2D array

Uploaded by

Swati Chawla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
88 views4 pages

Arrays Last Year Questions ONLY

1. Write a function to add corresponding elements of two equi-sized arrays and store the results in a third array 2. Write a function to add even positions of an array with the next element and increment odd positions by 10 3. Write a function to calculate the sum of the middle column elements of a 2D array 4. Write a function to calculate the sum of the middle row elements of a 2D array

Uploaded by

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

CHAPTER 9 - ARRAYS

1. Write a function in C++ to combine the contents of two equi-sized arrays A


and B by adding their corresponding elements as the formula A[i]+B[i];
where value i varies from 0 to N-1 and transfer the resultant content in the third same
sized array C.

2. Write the definition of a function AddUp(int Arr[], int N) in C++, in which all even
positions (i.e. 0,2,4,...) of the array should be added with the content of the element in
the next position and odd positions (i.e. 1,3,5,...) elements should be incremented by
10.
Example: if the array Arr contains
23 30 45 10 15 25
Then the array should become
53 40 55 20 40 35
NOTE:
● The function should only alter the content in the same array.
● The function should not copy the altered content in another array.
● The function should not display the altered content of the array.
● Assuming, the Number of elements in the array are Even.

3. Write a definition for a function SUMMIDCOL(int MATRIX[][10],int N,int M) in


C++, which finds the sum of the middle column’s elements of the MATRIX
(Assuming N represents number of rows and M represents number of columns, which
is an odd integer).
Example: if the content of array MATRIX having N as 5 and M as 3 is as
follows:
1 2 1
2 1 4
3 4 5
4 5 3
5 3 2
The function should calculate the sum and display the following:
Sum of Middle Column: 15

4. Write definition for a function ADDMIDROW(int MAT[][10],int R,int C) in C++,


which finds sum of the middle row elements of the matrix MAT (Assuming C
represents number of Columns and R represents number of rows, which is an odd
integer).
For example, if the content of array MAT having R as 3 and C as 5 is as follows:
1 2 3 4 5
2 1 3 4 5
3 4 1 2 5
The function should calculate the sum and display the following:
Sum of Middle Row: 15

5. Write the definition of a function FixPay(float Pay[], int N) in C++, which should
modify each element of the array Pay having N elements, as per the following rules:

1
Existing Value of Pay Pay to be changed to
If less than 100000 Add 25% in the existing value
If >=100000 and <20000 Add 20% in the existing value
If >=200000 Add 15% in the existing value

6. Write the definition of a function FixSalary(float Salary[], int N) in C++, which


should modify each element of the array Salary having N elements, as per the
following rules:
Existing Salary Value Required Modification in Value
If less than 100000 Add 35% in the existing value
If >=100000 and <20000 Add 30% in the existing value
If >=200000 Add 20% in the existing value

7. Write definition for a function SHOWMID(int P[][5],int R,int C) in C++ to display


the elements of middle row and middle column from a two dimensional array P
having R number of rows and C number of columns.
For example, if the content of array is as follows:

115 112 116 101 125


103 101 121 102 101
185 109 109 160 172
The function should display the following as output :
103 101 121 102 101
116 121 109
8. Write a function CHANGEO in C++, which accepts an array of integer and its size as
parameters and divide all those array elements by 7 which are divisible by 7 and
multiply other array elements by 3.
For example, if the array is :
21 12 35 42 18
The output will be:
3 36 5 6 54

9. Write a function REASSIGNO in C++, which accepts an array of integers and its size
as parameters and divide all those array elements by 5 which are divisible by 5 and
multiply other array elements by 2.

10. Write a function int SKIPSUM(int A[ ] [3], int N,int M) in C++ to find and return the
sum of elements from all alternate elements of a two dimensional array starting from
A[0][0].
For example, if the content of the array :
4 5 1
2 8 7
9 6 3
The function should add elements A[0][0], A[0][2], A[1][1],A[2][0],A[2][2]

2
11. Define a function SWAPCOL( ) in C++ to swap the first column elements with the
last column elements , for a two dimensional integer passed as the argument of the
function.

12. Define a function SWAPROW( ) in C++ to swap the first row elements with the last
row elements , for a two dimensional integer passed as the argument of the function.

13. Write a function SWAP2BEST (int ARR[],int Size) in C++ to modify the content of
the array in such a way that the elements, which are multiples of 10 swap with the
value present in the very next position in the array.
For example: If the content of array ARR is
90, 56, 45, 20, 34, 54
The content of array ARR should become
56, 90, 45, 34, 20, 54

14. Write code for a function void Convert(int T[ ], int Num) in C++, which repositions
all the elements of the array by shifting each of them one to one position before and
by shifting the first element to the last position.
For example, if the content of the Array is
22 25 70 32 12
The changed content will be:
25 70 32 12 22

15. Write a function in C++, which accepts an integer array and its size as 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

16. Write a function in C++ to print sum of all values which either are divisible by 2 or
divisible by 3 present in a 2D array passed as the argument of the function.

17. Write a function in C++ to print sum of all values which either are divisible by 3 or
divisible by 5 present in a 2D array passed as the argument of the function.

18. Write a function in C++ to find the sum of diagonal elements from a 2D array of type
float. Use the array and its size as parameters with float as its return type.

19. Write a user-defined function in C++ to display those elements of 2D array T[4][4]
which are divisible by 100. Assume the content of the array is already present and the
function prototype is as follows:
void showhundred( int T[4][4]);

20. Write a user-defined function named Lower_half() which takes 2D array A, with size
N rows and N columns as argument and prints the lower half of the array.

3
Eg:
Input:
2 3 1 5 0
7 1 5 3 1
2 5 7 8 1
0 1 5 0 1
3 4 9 1 5
Output:
2
7 1
2 5 7
0 1 5 0
3 4 9 1 5

21. Write a user-defined function in C++ to find and display the sum of diagonal
elements from a 2D array MATRIX[6][6] containing integers.

22. Write a user-defined function in C++ to find and display the multiplication of row
elements of two dimensional array A[4][6] containing integers.

23. Write a user-defined function in C++ to find and display the sum of row elements of
two dimensional array A containing integers.

24. Write a user-defined function in C++ to find and display the multiplication of column
elements of two dimensional array A[4][6] containing integers.

25. Write a user-defined function in C++ to find and display the sum of columns
elements of two dimensional array A containing integers.

26. Write a function in C++ to combine the contents of two equi-sized arrays A and B by
computing their corresponding elements with the formula 2*A[i]+3*B[i]; where value
I varies from 0 to N-1 and transfer the resultant content in the third same sized array.

27. 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 :
3 4 5 16 9
Output:
9 8 15 32 27
28. Write code for a function OddEven(int S[ ],int N) in C++ , to add 5 in all the odd
values and 10 in all the even values of the array S.
Example :
50 11 19 24 28
Output:
60 16 24 34 38

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy