-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrutas.c
76 lines (64 loc) · 1.36 KB
/
frutas.c
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <stdio.h>
#include <string.h>
/*
3
9.85
Mamao Maca Melao
2.65
Melancia
9.54
Pera Uva Goiaba
*/
void scan_valor(int i, double valor[])
{
double n;
scanf("%lf",&n);
valor[i] = n;
//printf("[%lf]:",valor[i]);
}
int scan_nome(int i, char nome[])//retorna o numero de frutas
{
int spaces = 0;
int palavra = scanf(" %[^\n]s",nome);
int tamanho = strlen(nome);
for (int k = 0; k < tamanho ; k++)
{
if(nome[k] == ' ' && k < tamanho-1)
{
spaces = spaces+1;
}
//printf("%c",nome[k]);
}
//printf(" Spaces = [%d]\n",spaces);
return spaces;
}
double media_rs(int i, int n_frutas, double valor[])
{
double media = valor[i]/n_frutas;
return media;
}
int main()
{
int dias;
scanf("%d",&dias);
double valor[dias];
char nome[1000001];
int total_frutas = 0;
double t = 0;
for (int i = 0; i < dias; i++)
{
scan_valor(i, valor);
int n_frutas = scan_nome(i, nome) + 1;
printf("dia %d: %d kg\n", i+1, n_frutas);
total_frutas = n_frutas + total_frutas;
}
for (int i = 0; i < dias; i++)
{
t = valor[i] + t;
}
double mean_rs = t/dias;
double mean_kg = (double)total_frutas/(double)dias;
printf("%.2lf kg por dia\n",mean_kg);
printf("R$ %.2lf por dia\n",mean_rs);
return 0;
}