Anda di halaman 1dari 3

Computer Science (083)

Ass #7 - 1-D, 2-D Array & User Defined Functions


1. Write a program in C++ that defines a function Sum (int[ ], int) which accepts an integer array
and its size as arguments and returns the sum of values stored in it.
2. Write a program in C++ that initializes the array and passes this array along with its size to a
function Average (int[ ], int) which returns the average of all the values stored in the array.
3. Write a program in C++ that defines a function Product (int[ ], int) which accepts an integer
array and its size as arguments and prints the product of values.
4. Write a program in C++ that defines a function Maximum (int[ ], int) which accepts an
integer array and its size as arguments and find out the maximum value stored in an array.
5. Write a program in C++ that defines a function Minimum (int[ ], int) which accepts an integer
array and its size as arguments and returns the minimum value stored in an array.
6. Write a program in C++ that defines a function Search_loc (int[ ], int,int) which accepts an
integer array, size and data to be searched as arguments. If the data is found, it returns the
location where data is present. Display the output with proper message.
7. An array P contains float values. Write a program in C++ that defines a function Search (float[
], int,float) which accepts a float array, its size and data to be searched as arguments. The
function should return an integer 0 to show the absence of the number and integer 1 to show
the presence of the number in the array. Display the output with proper message.
8. Write a program in C++ that defines a function Replace (int[] , int) which accepts an integer
array and its size as arguments and replaces elements having odd values with twice its value
and elements having even values with half its value.
Example:
If an array of five elements initially contains 3, 4, 5, 16, 9
Then the function should rearrange the contents of the array as 6, 2, 10, 8, 18
9. Write a program in C++ that defines a function ReverseArray(int [], int) which would accept
a one dimensional integer array NUMBERS and its size N. The function should reverse the
contents of the array without using the second array.
Note: Use the concept of swapping array
Example: If the array initially contains 2, 15, 3, 14, 7, 9, 19, 6, 1, 10
Then, after reversal the array should contain 10, 1, 6, 19, 9, 7, 14, 3, 15, 2
10. Write a C++ program that defines a function which accepts an integer array and its size as
arguments and swap the elements of every even location with its following odd location.
Example: If an array initially contains 2, 4, 1, 6, 5, 7, 9, 23, 10
Then the function should rearrange the array as 4, 2, 6, 1, 7, 5, 23, 9, 10

11. Write a C++ program that defines a function void SWAPCOL(int ARR[][], int m , int n ) in
C++ to swap (interchange) the first column elements with the last column elements for the two
dimensional array passed as the argument to the function. The main function should accept an
array and finally display the swapped array after calling SWAPCOL().
Example If the two dimensional
array contains
2
1
4
9
1
3
7
7
5
8
6
3
7
2
1
2

After swapping of the contents of


first
column and last column it should
be
9
1
4
2
7
3
7
1
3
8
6
5
2
2
1
7

12. Write a C++ program that defines a function void SWAPROW (int ARR[][], int m , int n ) in
C++ to swap (interchange) the first row elements with the last row elements for the two
dimensional array passed as the argument to the function. The main function should accept an
array and finally display the swapped array after calling SWAPROW ().
Example If the two dimensional
array contains
2
1
5
7

1
3
8
2

4
7
6
1

After swapping of the contents of first


row and last row it should be
7
2
1
2
1
3
7
7
5
8
6
3
2
1
4
9

9
7
3
2

13. Write a program in C++ that creates a function which accepts an integer one dimensional array
and its size as arguments and assigns the elements into a two dimensional array of integers in
the following format:
If the array is 1, 2,3,4,5
The resultant 2D array should be:
1
1
1
1
1

2
2
2
2
0

3
3
3
0
0

4
4
0
0
0

5
0
0
0
0

14. Write a program in C++ that creates a function which accepts an integer one dimensional array
and its size as arguments and assigns the elements into a two dimensional array of integers in
the following format:
If the array is 1, 2,3,4,5
The resultant 2D array should be:
1
1
1
1
1

0
2
2
2
2

0
0
3
3
3

0
0
0
4
4

0
0
0
0
5

Anda mungkin juga menyukai