63 lines
1.4 KiB
C
63 lines
1.4 KiB
C
#include <stdio.h>
|
|
|
|
int main(int argc, char const *argv[])
|
|
{
|
|
while (1)
|
|
{
|
|
int months = 0;
|
|
printf("Digite a quantidade de índices de audência que serão digitados:\n");
|
|
if (scanf("%d", &months) != 1)
|
|
{
|
|
return 1;
|
|
}
|
|
if (months < 0)
|
|
{
|
|
printf("Números negativos não são validos!");
|
|
return 1;
|
|
}
|
|
|
|
double input, last = 0, sum = 0;
|
|
int growing = 1;
|
|
|
|
for (int i = 1; i <= months; i++)
|
|
{
|
|
printf("Digite o índice do mês %d:\n", i);
|
|
if (scanf("%lf", &input) != 1)
|
|
{
|
|
return 1;
|
|
}
|
|
if (input < 0)
|
|
{
|
|
printf("Números negativos não são validos!");
|
|
return 1;
|
|
}
|
|
|
|
sum += input;
|
|
if (last > input)
|
|
{
|
|
growing = 0;
|
|
}
|
|
last = input;
|
|
}
|
|
|
|
double avarage = sum / months;
|
|
|
|
if (growing == 1)
|
|
{
|
|
printf("AUDIÊNCIA SEMPRE CRESCENTE. Média de audiência: %.1f\n", avarage);
|
|
}
|
|
else
|
|
{
|
|
printf("AUDIÊNCIA NEM SEMPRE CRESCENTE. Média de audiência: %.1f\n", avarage);
|
|
}
|
|
|
|
printf("Continuar? (S/N)\n");
|
|
char c;
|
|
scanf(" %c", &c);
|
|
if (c != 'S')
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
}
|