Given an array of length N, you need to find and print the sum of all elements of the array using function

 array sum

Given an array of length N, you need to find and print the sum of all elements of the array.

Input Format :
Line 1 : An Integer N i.e. size of array
Line 2 : N integers which are elements of the array, separated by spaces
Output Format :
Sum
Constraints :

1 <= N <= 10^6

Sample Input :
3
9 8 9
Sample Output :
26
C++ Code:
#include<iostream>
using namespace std;

int main(){
    int arr[1000000];
  int sum = 0;
  
  int n;
  cin>>n;
  for(int i=0;i<=n;i++)
  {
    cin>> arr[i];
  
  }
  for(int i=0;i<n;i++)
  {
    sum+=arr[i];
  }
  
  cout<<sum;
    
}



SHARE

Milan Tomic

Hi. I’m Designer of Blog Magic. I’m CEO/Founder of ThemeXpose. I’m Creative Art Director, Web Designer, UI/UX Designer, Interaction Designer, Industrial Designer, Web Developer, Business Enthusiast, StartUp Enthusiast, Speaker, Writer and Photographer. Inspired to make things looks better.

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment