Answer to Question #275834 in C for Tania Akter

Question #275834

Write a C Program to calculate the Average of an array elements where the elements are received as input.


1
Expert's answer
2021-12-05T11:22:27-0500
#include <stdio.h>

double Average(int a[], int size) {
    int i, sum=0;


    for (i=0; i<size; i++) {
        sum += a[i];
    }

    return (double)sum / size;
}

int main() {
    int arr[5];
    double avg;

    for (int i=0; i<5; i++) {
        printf("Enter value for %d-th element: ", i+1);
        scanf("%d", &arr[i]);
    }

    avg = Average(arr, 5);

    printf("Average value is %.2lf\n", avg);

    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 the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS