An array containing 5 integer elements is already provided for you in the code editor below.
Print out the cube of the 1st, 3rd, and 5th element of the given array.
Output
Multiple lines containing the cubes of the 3 elements of the given array.
-8
1
27
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
const int sz=5;
int* arr = new int[sz];
cout << "Please, enter 5 values: ";
for (int i = 0; i < sz; i++)
{
cin >> arr[i];
}
cout << "Multiple lines containing the cubes of the 3 elements of the given array:\n";
for (int i = 0; i < sz; i++)
{
if(i%2==0)
cout <<pow(arr[i],3) << endl;
}
}
Comments
Leave a comment