Problem with for, while and do while loops in C

1

/ * 10 positive integers are requested, calculate and show the following values, the sum of all the numbers read, the mean of the numbers, the largest number entered and the smallest number entered * /

I'm confused about how I can enter the average and determine how much is higher and which is less!

    
asked by Anthony Gelvez 11.12.2016 в 15:56
source

2 answers

0

you should store the numbers in a vector of 10 positions one number for each position and index it with the "i" and that accumulate in sum to get the biggest you have to do it in a for loop and the smaller one also separately and the average would be fine. did you understand?

    
answered by 11.12.2016 / 23:12
source
0

If you are able to calculate the sum you already have the average, since:

    media = suma / 10

To calculate the largest and the least you can create two variables and at each iteration the loop checks if the current number is greater than the largest and less than the smallest to update the value. For example:

     float numero, mayor, menor, suma;
     int i;

     printf("Dame un número: ");
     scanf("%d\n", &numero);
     mayor = menor = suma = numero;

     for (i = 1; i < 10; i++)
     {
         printf("Dame un número: ");
         scanf("%d\n", &numero);

         suma += numero;

         if (numero > mayor)
             mayor = numero;
         else if (numero < menor)
             menor = numero;
     }

     media = suma / 10;

I have not tried it, but you can get an idea by reading this code how to do it.

    
answered by 11.12.2016 в 16:18