Array Manipulation
Hope you can help me!
THANK YOU!!!
#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]<<" ";
}
}
Comments
Leave a comment