64 538
Assignments Done
99,3%
Successfully Done
In September 2018

Answer to Question #44347 in C for erico fire

Question #44347
Program to calculate sum and average of the elements stored in an array?
Expert's answer
#include <stdio.h>
int main()
{
    float someArray[5] = {1.2, 2.2, 2.3, 3.3, 3.6};
    float sum = 0; // sum of the elements stored in array
    float average; // average of the elements stored in array
    int i;
    int size = sizeof(someArray) / sizeof(someArray[0]); // size of array
    // loop to compute sum
    for(i = 0; i < size; i++) {
        sum = sum + someArray[i];
    }
    average = sum / size;
    //output
    printf("Array: ");
    for(i = 0; i < size; i++) {
        printf("%.3f ", someArray[i]);
    }
    printf("\n");
    printf("Sum: %.3f\n", sum);
    printf("Average: %.3f ", average);
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions