Calculates the average of some values taken from an array. - C Array

C examples for Array:Array Value

Description

Calculates the average of some values taken from an array.

Demo Code

#include <stdio.h>

int main (void){
    float values[10] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0};

    float sum, average;

    sum = 0.0;/* w  w w . j  a  v  a  2 s  .c o  m*/

    for (int n = 0; n < 10; ++n)
        sum += values[n];

    average = sum / 10;

    printf("%f", average);

    return 0;
}

Result


Related Tutorials