Write the code to display a table consisting of four rows and six columns. The first column should contain the numbers 1 through 4 raised to the first power. The second column should contain the result of raising the number in the first column to the second power. The third column should contain the result of raising the number in the first column to the third power, and so on. Use two for statements: one to keep track of the numbers 1 through 4, and the other to keep track of the powers (1 through 6).
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
for (int i = 1; i < 5; i++)
{
for (int n = 1; n < 7; n++)
{
cout << pow(i, n) << '\t';
}
cout << endl;
}
}
Comments
Leave a comment