summaryrefslogtreecommitdiff
path: root/userspace/add.c
blob: 04f7f178adbde7f1e0d057f0feac2c86af2fb238 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include "../fs/fs.h"
#include <math.h>

int main(int argc, char **argv) 
{

    float sum=0;
    float i=0;

    char *buf=malloc(256);
    puts("\n*** fools calculator ***");
    
    while(1)
    {
	printf("enter numer (or 'exit' to finish) %i: ",i+1);
        fgets(buf,255,stdin);

	if(buf[1]=='x')break;

	i++;
	sum+=atoi(buf);
    }

    if(i!=0)
    {
	puts("--------");
	printf("sum = %f \n",sum);
	printf("avg = %f \n",sum/i);
	printf("sin(avg) = %f \n\n",sin(sum/i));
    }

    return 0;
}