#include<iostream>
using namespace std;
double power (double n, int p=2)
{
double result=1;
for (int i=0;i<p;i++)
{
result *=n;
}
return result;
 }
 int main()
{
double n;
int p;
double result=0;

cout<<"enter n:";
cin>>n;
    cout<<"enter p:";
        cin>>p;
    if(p<0)
    {
        result=power(n);
        cout<<n<<"^2="<<result<<"\n\n";
    }
    else{
        result=power(n,p);
        cout<<n<<"^2="<<result<<"\n\n";
    }
    system("pause");
    return 0;
}
    

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: