Hallo knik 653!
May be you did mean something like this below?
Code:
#include <stdio.h>
#include <stdlib.h>
/** running average berechnet waehrend der Eingabe der Werte den Mittelwert
* und errechnet ihn nach jeder Eingabe neu */
#define max_n 5
double Input_Values(void);
double calc_sum(double werte[]);
void InitTemp(double (*werte)[max_n]);
void show_values(double werte[]);
void calc_average(void);
int main()
{
printf("Running average\n");
calc_average();
return 0;
}
double Input_Values(void)
{
double d = 0.0;
printf("Enter a double: ");
scanf("%lf", &d);
return d;
}
double calc_sum(double werte[])
{
int i;
double sum = 0.0;
for (i = 0; i < max_n; i++)
sum += werte[i];
return sum;
}
void InitTemp(double (*werte)[max_n])
{
int i;
for (i = 0; i < max_n; i++)
(*werte)[i] = 0;
}
void show_values(double werte[])
{
printf("Values of temps: temp[0]=%.3lf temp[1]=%.3lf temp[2]=%.3lf temp[3]=%.3lf temp[4]=%.3lf\n", werte[0], werte[1], werte[2], werte[3], werte[4]);
}
void calc_average(void)
{
double temps[max_n];
double sum = 0.0;
double average = 0.0;
int slei, i, n;
i = 0;
n = 1;
InitTemp(&temps);
for (slei = 0; slei < 10; slei++)
{
temps[i] = Input_Values();
sum = calc_sum(temps);
average = sum / n;
printf("i:%d n:%d sum:%.3lf arithmetically averaged: %.3lf\n", i, n, sum, average);
show_values(temps);
i++;
if(i >= max_n) i = 0;
if(n < max_n) n++;
}
}
It may be useful for example
to calculate the standard deviation of Parts how made with a lathe machine,
or a milling machine,
to use it for Shewhart individuals control charts
or anything.
Years ago i was skilled worker for quality assurance.
I hope, my example can help you.