Create a program for summing array elements. Enter and debug the program, analyze the result.
March 27, 2021 | education
| C ++ program:
#include <iostream>
using namespace std;
int main ()
{
setlocale (LC_ALL, “Russian”);
int n;
int Sum = 0;
cout << “Enter the number of elements in the array.” << endl;
cin >> n;
int a [n];
for (int i = 0; i <n; i ++) {
cout << “Enter the array element numbered:” << i + 1 << endl;
cin >> a [i];
Sum = Sum + a [i];
}
cout << “The sum of the array elements is:” << Sum << “.” << endl;
return 0;
}
You can analyze the operation of the program using simple tests:
1. Input data: 4 1 2 3 4. Result: 10.
2. Input data: 3 -4 5 1. Result: 2.
3. Input data: 2 -100 100. Result: 0.
One of the components of a person's success in our time is receiving modern high-quality education, mastering the knowledge, skills and abilities necessary for life in society. A person today needs to study almost all his life, mastering everything new and new, acquiring the necessary professional qualities.