• Lenguaje

    C

  • Descripción

    Gets the sum, the number of approbations, the average, the bigger, the position of the bigger, the number of disapprobations, the percentage of approbations, the percentage of disapprobations, the smallest, and the position of the smallest of N listed numbers.

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
#include <stdio.h>
#include <stdlib.h>

int main (void)
{
    const float approving_score = 7;
    float element, bigger = 0, smallest = 0, average = 0, amount = 0;
    float percentage_of_approved = 0, percentage_of_disapproved = 0;
    int i, n, smallest_position = 0, bigger_position = 0;
    int approved = 0, disapproved = 0;
    printf ("Enter the number of elements (n): ");
    scanf ("%d", &n);
    (void) getchar();
    for(i=1; i<=n; i++)
    {
        printf ("Enter the value of the element %d: ", i);
        scanf ("%f", &element);
        if (i==1 || element<smallest)
        {
            smallest = element;
            smallest_position = i;
        }
        if (i==1 || element>bigger)
        {
            bigger = element;
            bigger_position = i;
        }
        if (element < approving_score)
            disapproved++;
        else
            approved++;
        amount += element;
    }
    if (n > 0)
    {
        average = amount / n;
        percentage_of_approved    = (float)100 * approved    / n;
        percentage_of_disapproved = (float)100 * disapproved / n;
    }
    putchar ('\n');
    printf ("Smallest              : %g\n", smallest);
    printf ("Smallest position     : %d\n", smallest_position);
    printf ("Bigger                : %g\n", bigger);
    printf ("Bigger position       : %d\n", bigger_position);
    printf ("Sum                   : %g\n", amount);
    printf ("Average               : %g\n", average);
    printf ("Arithmetic mean       : %g\n", average);
    printf ("Approved              : %d\n", approved);
    printf ("Percentage of approved: %g%%\n", percentage_of_approved);
    printf ("Disapproved           : %d\n", disapproved);
    printf ("Percen. of disapproved: %g%%\n", percentage_of_disapproved);
    putchar ('\n');
    system ("pause");
    return EXIT_SUCCESS;
}