ProgIng - Programación en Ingeniería
Loading...
Searching...
No Matches
Ejemplo_035.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
Include dependency graph for Ejemplo_035.c:

Go to the source code of this file.

Functions

float sumar (float *X, int n)
float media (float *X, int n)
int main (void)

Function Documentation

◆ main()

int main ( void )

Definition at line 15 of file Ejemplo_035.c.

16{
17 int n, m, i;
18 float *A;
19 srand(time(NULL));
20 do{
21 printf("Ingrese el numero de elementos: ");
22 scanf("%d", &n);
23 }while(n<1);
24 do{
25 printf("Ingrese el numero de muestras: ");
26 scanf("%d", &m);
27 }while(m<1||m>n);
28 A = (float*)malloc(n*sizeof(float));
29 if(A==NULL)
30 return 1;
31 for(i=0; i<n; i++)
32 {
33 A[i] = (1.0*rand())/RAND_MAX;
34 printf("A[%d] = %f\t%p\n", i+1, A[i], A+i);
35 }
36 for(i=0; i<n-m; i++)
37 printf("u(%d) = %f\n", i+1, media(A+i, m));
38 free(A);
39 return 0;
40}
float media(float *X, int n)
Definition Ejemplo_035.c:10
Here is the call graph for this function:

◆ media()

float media ( float * X,
int n )

Definition at line 10 of file Ejemplo_035.c.

11{
12 return sumar(X, n)/n;
13}
float sumar(float *X, int n)
Definition Ejemplo_035.c:5
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sumar()

float sumar ( float * X,
int n )

Definition at line 5 of file Ejemplo_035.c.

6{
7 return n?X[0]+sumar(X+1,n-1):0;
8}
Here is the call graph for this function:
Here is the caller graph for this function: