#include <iostream>
using namespace std;
float Summa(int arr[], int start, int stop) {
float suma = 0;
for (int i = start; i < stop; i++)
{
suma += arr[i];
}
return suma;
void Show(int arr[], int start, int stop) {
cout << arr[i] << " ";
cout << endl;
int main()
srand(time(0));
const int size = 30;
int P[size];
for (int i = 0; i < size; i++)
P[i] = rand() % 50;
cout << "All arr : " << endl;
Show(P, 0, size);
cout << "First 15 elements : " << endl;
Show(P, 0, 15);
cout << "Average : " << (Summa(P, 0, 15) / 15) << endl;
cout << "Last 15 elements : " << endl;
Show(P, size - 15, size);
cout << "Average : " << (Summa(P, size - 15, size) / 15) << endl;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <iostream>
using namespace std;
float Summa(int arr[], int start, int stop) {
float suma = 0;
for (int i = start; i < stop; i++)
{
suma += arr[i];
}
return suma;
}
void Show(int arr[], int start, int stop) {
for (int i = start; i < stop; i++)
{
cout << arr[i] << " ";
}
cout << endl;
}
int main()
{
srand(time(0));
const int size = 30;
int P[size];
for (int i = 0; i < size; i++)
{
P[i] = rand() % 50;
}
cout << "All arr : " << endl;
Show(P, 0, size);
cout << "First 15 elements : " << endl;
Show(P, 0, 15);
cout << "Average : " << (Summa(P, 0, 15) / 15) << endl;
cout << "Last 15 elements : " << endl;
Show(P, size - 15, size);
cout << "Average : " << (Summa(P, size - 15, size) / 15) << endl;
}