(2) 10') Write a program to calculate the average of all elements in array a. array a should be defined as: int a[10]={21,13,4,35,16,17,8,19,20,7}; ( 2 ) 10 ' ) Write a program to calculate the average of all elements in array a . array a should be defined as : int a [ 10 ] = { 21,13,4,35,16,17,8,19,20,7 } ;​

Respuesta :

Using the code in computational language in C++ it is possible to write a program that organizes the given array defining the elements.

Writing code in C++:

#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;

}

See more about C++ code at brainly.com/question/19705654

#SPJ1

Ver imagen lhmarianateixeira