mirror of
https://github.com/mirror/tinycc.git
synced 2024-12-28 04:00:06 +08:00
28 lines
397 B
C
28 lines
397 B
C
#include <stdio.h>
|
|
|
|
typedef struct
|
|
{
|
|
double average;
|
|
int count;
|
|
}
|
|
stats_type;
|
|
|
|
static void
|
|
testc (stats_type *s, long long data)
|
|
{
|
|
s->average = (s->average * s->count + data) / (s->count + 1);
|
|
s->count++;
|
|
}
|
|
|
|
int main (void)
|
|
{
|
|
stats_type s;
|
|
|
|
s.average = 0;
|
|
s.count = 0;
|
|
testc (&s, 10);
|
|
testc (&s, 20);
|
|
printf ("%g %d\n", s.average, s.count);
|
|
return 0;
|
|
}
|