i have a problem in the result of the average in the function calcular, not return a correct number, and the rand return values equals, i dont know the reason for the bad average
#include <stdio.h>
#include <stdlib.h>
int calcular(int * _arreglo, int * _tam);
int main(int argc, char * argv[]) {
int tam = 0;
if (argc == 2) {
tam = atoi(argv[1]);
} else {
printf("No se ha ingresado correctamente el tamaño \n");
exit(1);
}
int * arreglo;
arreglo = (int * ) malloc(sizeof(int) * tam);
int i;
for (i = 0; i < tam; i++) {
arreglo = (int * )(rand() % 101);
printf("soy %d \n", ((int)(arreglo)));
arreglo++;
}
int promedio = calcular(arreglo, & tam);
printf("Promedio: %d \n", promedio);
free(arreglo);
return 0;
}
int calcular(int * _arreglo, int * _tam) {
int pro = 0;
int i;
_arreglo = _arreglo - ( * _tam);
for (i = 0; i < * _tam; i++) {
pro = pro + ((int)(_arreglo));
_arreglo++;
}
return (pro / ( * _tam));
}