Find Sum of Array Elements in C++

Advertisements

Prev Tutorial Next Tutorial

C++ Program to Find Sum of an Array Elements

Sum of all Array elements means add all array Elements. Suppose we have 4 Elements in array and we want to find there sum.
arr[0]=4
arr[1]=2
arr[2]=1
arr[3]=6
Sum off all above elements are
arr[0]+arr[1]+arr[2]+arr[3]=4+2+1+6=13

C++ program to Find Sum of an Array Elements


#include<iostream.h>
#include<conio.h>

 void main()
  {
   int arr[20],i,n,sum=0;
   clrscr();
   cout<<"How many elements you want to enter: ";
   cin>>n;
   cout<<"Enter any "<<n<<" elements in Array: ";
   for(i=0;i<n;i++)
   {
   cin>>arr[i];
   }
   cout<<"Sum of all Elements are: ";

   for(i=0;i<n;i++)
   {
    sum=sum+arr[i];
   }
   for(i=0;i<n;i++)
   {
   }
  cout<<sum;
  getch();
  }

Output

How many elements you want to enter : 5
Enter any 5 elements in Array: 
1 4 2 7 5
Sum of all Elements are: 19 

Prev Tutorial Next Tutorial

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements