Program to calculate sum and average of the elements stored in an array?
1
Expert's answer
2014-07-23T11:13:19-0400
#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; }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments
Leave a comment