Arrays Last Year Questions ONLY
Arrays Last Year Questions ONLY
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.
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
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