Answer to Question #194613 in C++ for jay

Question #194613

1. Write a program to store integer elements in an array named test of size 10 with initial values (5,9,57,3,9,21,57,6,9,3) and print it.

 2. Modify the program to read to display the array contents in reverse order. 

 3. Modify the program to find the sum of all elements of the array. 

4. Modify the program to copy the elements from the test array into another array named testcopy. 

8. Modify the programs to count and display the frequency of each element of array test.

9. Modify the program to find the maximum and minimum element in array test.  



1
Expert's answer
2021-05-17T16:43:32-0400
#include <iostream>
 
using namespace std;
 
int main()
{
	int test[] = { 5, 9, 57, 3, 9, 21, 57, 6, 9, 3 };
	int size = 10;
	cout << "Initial array: ";
	for (int i = 0; i < size; i++)
	{
		cout << test[i] << " ";
	}
	cout << endl << "Reverse array: ";
	for (int i = size - 1; i >= 0; i--)
	{
		cout << test[i] << " ";
	}
	int sum = 0;
	for (int i = 0; i < size; i++)
	{
		sum += test[i];
	}
	cout << endl << "Sum of all elements is: " << sum << endl;
	int testcopy[10];
	for (int i = 0; i < size; i++)
	{
		testcopy[i] = test[i];
	}
	cout << "Copy array: ";
	for (int i = 0; i < size; i++)
	{
		cout << testcopy[i] << " ";
	}
	int clone[100];
	for (int i = 0; i < 100; i++)
	{
		clone[i] = 0;
	}
	for (int i = 0; i < size; i++)
	{
		clone[test[i]]++;
	}
	cout << endl;
	for (int i = 0; i < 100; i++)
	{
		if (clone[i] != 0)
		{
			cout << "Element " << i << " meet in test array: " << clone[i] << " times." << endl;
		}
	}
	int min, max;
	min = max = test[0];
	for (int i = 1; i < size; i++)
	{
		if (test[i] > max) max = test[i];
		if (test[i] < min) min = test[i];
	}
	cout << "Min value in test array is: " << min << endl;
	cout << "Max value in test array is: " << max << endl;
	system("pause");
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog