C program to Calculate the average of array elements

Problem Statement: Calculate the average of array elements

/*C program to print the average of array elements*/
#include <stdio.h>
int main()
{
    int n;
    printf("Enter the number of element\t");
    scanf("%d", &n);
    int array[n], sum = 0;
    printf("Enter array elements\n");
    for (int i = 0; i < n; i++)
        scanf("%d", &array[i]);
    for (int i = 0; i < n; i++)
        sum = sum + array[i];
    printf("Average of array elemsnts is %f", (float)sum/n);

    return 0;
}
$gcc array.c
$ ./a.out
Enter the number of element 6
Enter array elements
22
32
3
61
2
45
Average of array elemsnts is 27.500000$
Time complexity:O(n)

also see

C Programming language
Go Programming language
Linked List Array
Stack Queue
Puzzle Reasoning
Aptitude HTML

 

Previous articleC Program to Calculate Sum of an Array
Next articleQueue using Linked List

LEAVE A REPLY

Please enter your comment!
Please enter your name here