Sunday 8 July 2012

How to calculate the average of all the values in the array



This is the source code to calculate the average of all the values in the array
#include<iostream.h>
#include<conio.h>
main()
{
      int A[5]={3,6,9,12,15};
      int sum;
      float average;
      sum=A[0]+A[1]+A[2]+A[3]+A[4];
      average=sum/5;
      cout<<"Average="<<average<<endl;
      getch();
      }
End

No comments:

Post a Comment