// promedio.c, promedio de n #s reales #include #include #define MAX 1000 // maximo de valores int pideCantidad(int m); void pideValores(float v[], int n); float promedio(float v[], int c); int main() { int can; // cantidad de valores float val[MAX]; // los valores float pro; // promedio printf("Promedia N numeros reales.\n\n"); can = pideCantidad(MAX); pideValores(val, can); pro = promedio(val, can); printf("\nPromedio: %.2f\n\n", pro); system("pause"); return 0; } int pideCantidad(int m) { // pide la cantidad de valores int c; // cantidad de valores a pedir (1 a m) do { printf("Cantidad de valores (1 a %d): ", m); scanf("%d", &c); } while ( c < 1 || c > m); return c; } void pideValores(float v[], int n) { // pide n valores reales int p; // posicion en el arreglo ( 0 a n-1) for (p = 0; p < n; p++) { printf("Valor # %d: ", p+1); scanf("%f", &v[p]); } } float promedio(float v[], int c) { // promedia c valores float pr = 0; // promedio (suma, inicialmente) int p; // posicion en v[] for (p = 0; p < c; p++) pr += v[p]; pr /= c; return pr; }