Take an array of size 5x5 and initialize it with random numbers of range 1 to 10, now add all the elements of the 2D array and display sum.
Modify part a in such a way that you have to find individual sum of each row of the 2D array and store corresponding result in 1D array i.e. sum of all the elements of row 0 should be stored in 1st element of 1D array, similarly sum of all elements of the second row of 2D array should be stored at the second
index of 1D array. Display the final sum array (i.e. 1D array). Think about the size of 1D array yourself.
Example:
Array:
2 3 5 3 1
4 5 1 2 1
4 7 3 2 0
2 1 1 5 1
1 7 8 9 0
Sum array:
14 13 16 10 25
Perform sum of all the elements of the arrays whose row number and column number both are odd. Display the final sum.
Array:
2 3 5 3 1
4 5 1 2 1
4 7 3 2 0
2 1 1 5 1
1 7 8 9 0
Sum: 13
We have a 4 x 4 two dimensional array. Fill it with random values from 1 to 100. Write a code to take transpose of the matrix. The following array is shown as an example:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
BECOMES
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12 16
Create an array of size 5x5 first fill the array with random values between 1 and 100, print it in straight and reverse order. Then fill that array from the user, print it in straight and reverse order.
Create an array of size 10 fill the array from the user. Then ask the user for the order of sorting ascending or descending. And sort the array using bubble sorting algorithm.
Write a program that declares 2 integer arrays x, y of size 10 each. The program then reads values for x and y arrays from the user (use some common values).
Finally the program finds the common values in x and y and prints them. If there is no common values in x and y print “There is nothing common between array x and y”.
Your boss sent you a notepad file called numbers.txt containing an
unknown number of integers. He requests you to write a single program
that a) reads these numbers into an array b) checks whether the file
has correctly opened c) prints out the average of all the numbers in the
array d) then program should search the array to see whether integer 150
is present e) finally the program should print out all the positive numbers
in the array. [20]
Create a class called Cuboid with the data members: length (float), breadth (float) and height (float). Use an inline function and calculate the area of the base using the formula = length * breadth and print it.
Define another member function and calculate the total surface area of the cube using the formula = 2*(length*breadth + breadth*height + height*length) and print it.
Define a friend function to calculate the volume of the cuboid using the formula = length*breadth*height. After calculating the volume, calculate the amount of liquid that can be stored if 1𝑚3 can store 100 liters of liquid.
Write a program to:
a) Initialize an array of 8 entries for serial number.
b) Set the value of 5th serial number to 89.
c) Set the value of 3rd serial number to the addition of first two serial numbers.
d) Display the serial number on 2nd index
e) Print the whole array
Write a program that dynamically allocates an array large enough to hold a user-defined number of test
scores. Once all the scores are entered, the array should be passed to a function that sorts them in
ascending order. Another function should be called that calculates the average score. The program
should display the sorted list of scores and averages with appropriate headings. Use pointer notation
rather than array notation whenever possible.
Input Validation: Do not accept negative numbers for test scores.
Example
Enter the number of test scores: 4
Enter each test score:
Test#1: 34
Test #2: 73
Test #3: 22
Test #4: 89
Sorted test scores:
Test #1: 22
Test #2: 34
Test #3: 73
Test #4: 89
Average = 54.5
Find the errors
int sum(int x, int y)
{
int result; result = x + y;
}