I am programming a method that finds the average, the maximum of 100 numbers that are stored in a vector.
Next, I show the code that I am doing.
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int points[100];
int main()
{
int i;
int k=sizeof(points)/sizeof(int);
double points_moy(int[]);
int points_max(int[]);
for (i = 0; i < k; i++) {
points[i] = rand()%121;
printf("%i-",points[i]); //I show the vector
}
printf("\n mean=%f\n", points_moy(points)); // I show the mean
printf("\n max=%i \n", points_max(points));// I show the max,
//here is the
//"error"
return 0;
}
double points_moy( int points[]) {
int sum=0, i;
int m=sizeof(points)/sizeof(int);
for(i=0; i<m; i++){
sum=sum+points[i];
}
return((float)sum/m);
}
int points_max(int vec[]) {
int i;
int max=vec[0];
int len=sizeof(vec)/sizeof(int);
for (i = 0; i < len; i++) {
if (vec[i] > max) {
max = vec[i];
}
}
return max;
}
Create the method to find the maximum, but at the moment of calling it and compiling the algorithm, it shows me an incorrect value (in most compilations max = 7 but it should be max = 119).
I do not know if the function points_max has any problem, or when calling the function in the main the error is generated.