How to find the sum of an Array elements in c++

 

c++ program to find and print the sum of array elements
c++ program to find and print the sum of array elements

How to find the sum of an Array elements in c++:                                                                    

This is a c++ program to find and print the sum of array elements.This program is about How to find the sum of an Array elements in c++.In c++ you can find the sum of an array elements.You can find and print the sum of an array elements in c++ by this program.                                                                             

Program to find the sum of an array elements in c++:              

1)#include<iostream>
2)using namespace std;
3)int main()
4){
5)int arr[5],sum;
6)for(int i=0;i<5;i++){
7)cout<<"enter any numbers=";
8)cin>>arr[i];
9)}
10)cout<<"the values in arrays are:";
11)for(int i=0;i<5;i++)
12)cout<<arr[i]<<endl;
13)sum=arr[0]+arr[1]+arr[2]+arr[3]+arr[4];
14)cout<<"sum of arrays is:"<<sum;
15)return 0;
16)}

c++ program to find and print the sum of array elements
c++ program to find and print the sum of array elements


DESCRIPTION:
You can find the sum of an array elements in c++ by this programe.This is a programe to find the sum of an array elements.

Finding the sum of the elements in an array is a common task in C++, and there are a few different ways that you can do it. In this blog post, we'll go over two methods for calculating the sum of an array: using a for loop and using the std::accumulate function from the C++ Standard Library.

Method 1: Using a for loop

One way to find the sum of the elements in an array is to use a for loop to iterate over the elements and add them up one by one.

Method 2: Using std::accumulate

Another way to find the sum of the elements in an array is to use the std::accumulate function from the C++ Standard Library. This function takes an input range (in this case, the array) and a starting value (in this case, 0), and returns the accumulated result of applying a given operation to the elements in the range (in this case, addition).



Post a Comment

0 Comments