You are given an array of n integers and a natural number k. Calculate the arithmetic mean of the values

You are given an array of n integers and a natural number k. Calculate the arithmetic mean of the values of the elements located between the minimum by value element and the kth element of the array. in C ++

#include <iostream>
using namespace std;
int a [1000];
int n, p, k, i, m = 1000, s = 0, kol = 0;
int main ()
{

cin >> n; // enter the number of elements
cin >> k;
for (i = 0; i <n; i ++)
{
cin >> a [i];
if (a [i] <m) {m = a [i]; p = i;} // find the minimum and its number
}
if (p> k) for (i = k; i <= p; i ++)
{
s = s + a [i]; kol ++; // calculate the amount and quantity
}
else for (i = p; i <= k; i ++)
{
s = s + a [i]; kol ++;
}
cout << s / double (kol) << endl; // display the arithmetic mean
return 0;
}



One of the components of a person's success in our time is receiving modern high-quality education, mastering the knowledge, skills and abilities necessary for life in society. A person today needs to study almost all his life, mastering everything new and new, acquiring the necessary professional qualities.