0

Help add up the elements in the array.

#include <iostream> #include <math.h> using namespace std; int main() { const int size = 9; int arr[size]; arr[0] = 2; cout << "Your array: "; for (int i = 0; i < size; i++) cout << pow(arr[0], i) << ' '; }

10th Feb 2021, 4:51 PM
Аня Ли
Аня Ли - avatar
4 Réponses
0
#include <iostream> #include <math.h> using namespace std; int main() { const int size = 9; int arr[size]; arr[0] = 2; int sum=0; cout << "Your array: "; for (int i = 0; i < size; i++){ sum+=arr[i]; } cout<<sum; }
10th Feb 2021, 5:08 PM
Atul [Inactive]
0
Like this??
10th Feb 2021, 5:08 PM
Atul [Inactive]
0
No.Atul There are two task. 1. Fill an array of 10 elements powers of two. ( I did this.) Array (1 2 4 8 16 32 64 128 256) 2. Calculate the sum of the numbers from the array obtained in the first task.
10th Feb 2021, 5:16 PM
Аня Ли
Аня Ли - avatar
0
Sum of 1 2 4 8....?
10th Feb 2021, 5:27 PM
Atul [Inactive]