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
#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;
}
}
Comments
Leave a comment