C++ Program to Add Elements of an Array

C++ Program to Add Elements of an Array

Write C++ Program to Add Elements of an Array

// CPP Program to Add Elements of an Array

#include <iostream>

using namespace std;

int main()
{
	int A[5];
	int i, sum = 0;

	for(i = 0; i < 5; i++)
	{
		cout << "Enter A[" << i << "] :--> " ;
		cin >> A[i];

		sum = sum + A[i];
	}

		cout << "The sum of the array elements is :--> " << sum;

	return 0;
}

Output:

Enter A[0] :--> 1
Enter A[1] :--> 2
Enter A[2] :--> 3
Enter A[3] :--> 4
Enter A[4] :--> 5
The sum of the array elements is :--> 15