calculating squares of an array

Jul 9, 2018 at 11:39pm
Hello, I'm completely new at this and I'm not sure how to calculate the square of the elements of an array of 4 numbers?
Jul 10, 2018 at 12:52am
int a[4] = {1,2,3,4};
for(int x = 0; x < 4; x++)
cout << a[x]*a[x] << endl;

you can compute more complicated powers with the pow() function, but here a multiply is all you need, and it illustrates accessing the array.

Topic archived. No new replies allowed.