Sunday 8 July 2012

How to calculate the sum of all values in an array



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

1 comment: