Starting from:

$34.99

CS103 Assignment 1 Solution

ASSIGNMENT - I
1. Create an array of integers with dynamic memory allocation. The size of the arrayis a user input. Read the elements of the array as inputs. Perform the following operations on the elements of the array using a separate function for each operation:
(a) Print the elements of the array.
(b) Find the indices of the maximum and the minimum element of the array. Letthe name of the function be findMinMax. It should return a (dynamically created) array of two elements, such that, the first element is the index of the minimum value and the second element is the index of the maximum value.
(c) Write a function swapMinMax to swap the maximum and the minimum element of the array. swapMinMax must make use of findMinMax.
(d) Find the sum of all the elements of the array. Let the name of the function besum.
(e) Find the average of all the elements of the array. It must make use of sum.
(f) Write a function find that would return the index of a given value (user input) in the array. If the value is not present in the array, it should return −1.
(g) Print the address of each element of the array.
2. Write a function to dynamically allocate the memory of a lower triangular matrix.The number of elements of the ith row should be i. Write another function to make the allocated memory free.
3. Write a function to dynamically allocate a two-dimensional matrix. Take two twodimensional matrices as user inputs. Let the size of the matrices be m × n and n × p, respectively. Write a function to multiply the matrices. It should dynamically allocate the memory for the m × p resultant matrix and should return a pointer to the matrix.

More products