Answer to Question #345738 in C++ for Shabbar

Question #345738

Write a C++ program that calculates the nth power of numbers from 1 to k. where n

and k will be input by user.

Expected Output:

Input Power value , n: 3

Input k : 5

3rd power of 1 is 1

3rd power of 2 is 8

3rd power of 3 is 27

3rd power of 4 is 64

3rd power of 5 is 125


1
Expert's answer
2022-05-30T08:15:55-0400
#include <iostream>
#include <cmath>


using namespace std;


int main()
{
	int n, k;
	cout << "Input Power value , n: ";
	cin >> n;
	cout << "Input k : ";
	cin >> k;
	for (int i = 1; i <= k; i++)
	{
		cout << n << "rd power of " << i << " is " << pow(i, n) << endl;
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS