Compute the average of a set of values : int array « Data Types « C++ Tutorial






#include <iostream>   
using namespace std;   
   
int main()   
{   
  int i, avg, min_val, max_val; 
  int nums[10];   
   
  nums[0] = 13;   
  nums[1] = 18;   
  nums[2] = 75;   
  nums[3] = 120;   
  nums[4] = 1321;   
  nums[5] = 56;   
  nums[6] = 13124;   
  nums[7] = 12123;   
  nums[8] = -19312;   
  nums[9] = 88123;   
   
  // compute the average 
  avg = 0; 
  for(i=0; i<10; i++) 
    avg += nums[i]; 
 
  avg /= 10; 
  
  cout << "Average is " << avg << '\n';   
 
  return 0;   
}
Average is 9566








2.4.int array
2.4.1.int array declaration
2.4.2.Compute the average of a set of values
2.4.3.Find the minimum and maximum of a set of values