Вы находитесь на странице: 1из 12

ARRAYS

Write a program to insert the given elements in appropriate position


after creating 1 D array. Array should be in sorted order(ascending
order). Max size of an array is 50.

For e.g:

How many elements do u want to create array with?(max size:50) = 6

Enter Array elements(must be sorted in Asc order)

2 6 9 10 12 15

Enter element to be inserted …= 11

Want to insert more elements?(y/n) …= y

Enter elements to be inserted….= 4

Want to insert more elements?(y/n) …= n

The array now is as shown below:

2 4 6 9 10 11 12 15
Write a program to delete the given elements in appropriate position
after creating 1 D array. Array should be in sorted order(ascending
order). Max size of an array is 50.

For e.g:

How many elements do u want to create array with?(max size:50) = 6

Enter Array elements(must be sorted in Asc order)

2 6 9 10 12 15

Enter element to be inserted …= 9

The array now is as shown below:

Zero(0) signifies deleted elements

2 6 0 10 12 15

After this emptied space will be shifted to the end of array

Want to insert more elements?(y/n) …= n

The array now is as shown below:

2 6 10 12 15
Passing Array and size as arguments
1) Print the numbers and sum of numbers whose
unit place is 2.
e.g: if an array is 12, 3, 2, 32, 25 then
output is : 12 , 2, 32 and sum =12+2+32 = 46
2) Given an array named A with following
elements:
3, -5, 1, 3, 7, 0, -15, 3, -7, -8
Write a C++ function to shift all the negative to left
so that the resultant array look like:
-5, -15, -7, -8, 3, 1, 3, 7, 0, 3
3) Write a function CHANGE( ) 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.
Sample Input Date of the array
A[O] A[1] A[2] A[3] A[4]
21 12 35 42 18
Content of the array after calling CHANGE( ) function
A[O] A[1] A[2] A[3] A[4]
3 36 5 6 54
4) 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 function should rearrange the content of the array as
9, 8, 15, 32, 27
Quest) Write a function swaptobest( ) in C++ which accepts an
integer array and its size as arguments 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.
e.g: if input array is :90, 56,45,20,34,54
then output array is: 56,90,45,34,20,54

Quest) Write a function sorting( ) in C++ which accepts an


integer array and its size as arguments and arrange the elements
in ascending order.
e.g: if input array is : 10,22,1,15,17,8
then output array is : 1,8,10,15,17,22
Quest) Given two arrays of integers A and B of sizes M and N respectively.
Write a function named MIX () with four arguments, which will produce a
third array named C. such that the following sequence is followed.
- All even numbers of A from left to right are copied into C from left to
right.

- All odd numbers of A from left to right are copied into C from right to
left.

- All even numbers of B from left to right are copied into C from left to
right.

- All old numbers of B from left to right are copied into C from right to
left.

- A, B and C are passed as arguments to MIX (). e.g., A is {3, 2, 1, 7, 6, 3}


and B is {9, 3, 5, 6, 2, 8, 10} the resultant array C is {2, 6, 6, 2, 8, 10, 5, 3, 9,
3, 7, 1, 3}
Q) Write a Program in C++ which accepts a 2D array of integers
and its size as arguments and displays the elements and sum of
elements which lie on diagonals.
[Assuming the 2D Array to be a square matrix with odd
dimension i.e. 3×3, 5×5, 7×7 etc.

Q) Write a Program in C++ which accepts a 2D array(odd


matrices) of integers and its size as arguments and print the sum
of middle row and middle column elements separately.

Q) Write a Program in C++ to input a matrices(2 D arrays) and


print elements of upper triangle and lower triangle matrix as
given below:
If input matrix is:
1 2 3
4 5 6
7 8 9

then upper triangle matrix is: lower triangle matrix is:


2 3
6 4
7 8
Q) Write a Program in C++ to input two matrices(2 D arrays)
and perform multiplication of elements of both the matrices
using given below formula:
If first matrix is : if Second matrix is:
1 2 3 1 2 3
4 5 5 4 5 6
7 8 9 7 8 9

Then multiplication matrix is :

30 36 42

66 81 96

102 126 150


Q) Write the definition of a user-defined function REPEAT_ROW(int A[][],int R, int C) in
C++ that will store the elements in the following manner :

1. All row elements except the 1st element replaced by the 1st element,
2. All row elements except the 1st & 2nd element replaced by the 2nd element,
3. All row elements except the 1st, 2nd & 3rd element replaced by the 3rd element and so on.
For example: if initially the array was:-
5 6 10 2
2 6 9 12
18 14 5 6
Then, the contents of the array after execution of the above function will be:-
5 5 5 5
2 6 6 6
18 14 5 5

Q) Write a program in C++ to input two one dimensional arrays of


integers and transfer the elements of both the arrays into third 1-D
array in ascending order: eg
Is first array is: 1,4,7,14,20 and second array is: 1,3,7,10,25

Then third array will be:

1, 1, 3, 4, 7, 7, 10, 14, 20, 25(Merge Sort)


Q) Write a program in c++ to input an one dimensional of given size and an
element then search an element using Binary Search Operation. In Binary Search
first input an array then perform sorting and sort array in ascending order then
search an element using binary search just like search page number in a book or
search any word in a dictionary.

e.g: if input array is:


24 12 8 17 25 35 6 11 87 9

Then first perform normal sorting technique


6 8 9 11 12 17 24 25 35 87
0 1 2 3 4 5 6 7 8 9

Then input a number that to be searched and perform Binary search


Q) Write a user-defined function swap_row(int ARR[ ][3],int R,int C) in C++ to swap the first
row values with the last row values:
For example if the content of the array is:
10 20 30
40 50 60
70 80 90
Then after function call, the content of the array should be:
70 80 90
40 50 60
10 20 30

Вам также может понравиться