You can implement a function that can calculate the arithmetic mean of a vector of integers using only elements that have a value below the established limit, see:
double media( int v[], int tam, int limite )
{
int i = 0;
double n = 0.0;
int soma = 0;
double med = 0.0;
for( i = 0; i < tam; i++ )
{
if( v[i] > limite )
{
soma += v[i];
n++;
}
}
med = soma / n;
return med;
}
To determine the highest and lowest values contained in an integer vector you can implement specific functions:
int maior( int v[], int tam )
{
int i = 0;
int n = INT_MIN;
for( i = 0; i < tam; i++ )
if( v[i] > n )
n = v[i];
return n;
}
int menor( int v[], int tam )
{
int i = 0;
int n = INT_MAX;
for( i = 0; i < tam; i++ )
if( v[i] < n )
n = v[i];
return n;
}
Putting it all together:
#include <stdio.h>
#include <limits.h>
double media( int v[], int tam, int limit )
{
int i = 0;
double n = 0.0;
int soma = 0;
double med = 0.0;
for( i = 0; i < tam; i++ )
{
if( v[i] < limit )
{
soma += v[i];
n++;
}
}
med = soma / n;
return med;
}
int maior( int v[], int tam )
{
int i = 0;
int n = INT_MIN;
for( i = 0; i < tam; i++ )
if( v[i] > n )
n = v[i];
return n;
}
int menor( int v[], int tam )
{
int i = 0;
int menor = INT_MAX;
for( i = 0; i < tam; i++ )
if( v[i] < menor )
menor = v[i];
return menor;
}
int main( void )
{
int vet[] = { 1, 3, 5, 7, 9, 2, 4, 6, 8, 10, 1 };
int tam = sizeof(vet) / sizeof(int);
printf("Maior: %d\n", maior( vet, tam ) );
printf("Menor: %d\n", menor( vet, tam ) );
printf("Media: %g\n", media( vet, tam, 6 ) );
return 0;
}
Output:
Maior: 10
Menor: 1
Media: 2.66667