//C++ program to calculate x^n
#include<iostream>
using namespace std;
int main()
{
int n,x,k;
cout<<"Enter X value : ";
cin>>x;
cout<<"Enter N value : ";
cin>>n;
int y=1;
for(int i=0;i<n;i++)
{
y=y*x;
k=y;
}
cout<<"Power("<<x<<","<<n<<") = "<<k<<endl;
return 0;
}
Output will be similar to this :
Similar program(s):
C++ program to calculate x power n(X^N) using recursion


No comments:
Post a Comment