Spread the post

C program to calculate sum and average of an array

Help of this post we are learning how to calculate sum and average of an given array. Suppose given contain following element.

Stack AreamainarraySum and Average [0] 23 [1] 5 [2] 21Sum [669]Average [55] [3] 51 [4] 111 [5] 34 [6] 12 [7] 121 [8] 44 [9] 22 [10] 113 [11] 112size (int) =12

Time complexity of this program O(n)

Below in C implementation of this problem. Iterative approach.

Accepted Output

Data of Array is: 34, 21, 5, 52, 32, 12, 42, 12, 323, 33, 12, 344, 23

Sum of array is : [945]

Average of array is: [72]

Data of Array is: 23, 5, 21, 51, 111, 34, 12, 121, 44, 22, 113, 112

Sum of array is : [945]

Average of array is: [72]

Output
 Data of Array is:  23 5 21 51 111 34 12 121 44 22 113 112
 Sum of array is : [669]
 Average of array is: [55]
  

Spread the post

Recommended Posts: