Answer to Question #349397 in C++ for Lilienne

Question #349397

Array Manipulation

  1. Initialize 8 element arrays into a 2D array
  2. Initialize array {{2, 69}, {42, 8}, {8, 11}, {8, 8}};
  3. After initializing the arrays, find the largest element
  4. Find the smallest element.
  5. After displaying the outputs, sum all the elements, and the results displayed must be 156.
  6. Lastly, sort the element.
  7. You need to traverse the arrays.

Hope you can help me!

THANK YOU!!!



1
Expert's answer
2022-06-09T09:58:40-0400
#include <iostream>
#include <algorithm>


using namespace std;


int main()
{
	int arr[8]={ 2, 69, 42, 8 , 8, 11, 8, 8};
	int larg = arr[0];
	int smal = arr[0];
	for (int i = 0; i < 8; i++)
	{
		if (arr[i] > larg)
			larg = arr[i];
		if (arr[i] < smal)
			smal = arr[i];
	}
	cout << "The largest element is " << larg<<endl;
	cout << "The smallest element is " << smal << endl;
	int sum = 0;
	for (int i = 0; i < 8; i++)
	{
		sum+=arr[i];
	}
	cout << "The sum of elements is " << sum << endl;
	sort(&arr[0], &arr[8]);
	cout << "Sorted elements: ";
	for (int i = 0; i < 8; i++)
	{
		cout<<arr[i]<<" ";
	}
}

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
APPROVED BY CLIENTS