You are on page 1of 1

#include<iostream>

using namespace std;


int main()
{
int p;
char choice;
double n,ans;
double power(double x,int y);
cout<<"press 'a' if u want to calculate other than square";
cin>>choice;
if(choice == 'a')
{
cout<<"enter the value of n and p";
cin>>n>>p;
ans=power(n,p);
cout<<"answer is :"<<ans;
}
else
{
cout<<"enter the value of n";
cin>>n;
ans=power(n,2);
cout<<"answer is :"<<ans;
}
return 0;
}
double power(double n,int p)
{
int i;
i=1;
double ans=1;
for(i=1;i<=p;i++)
{
ans=ans*n;
}
return ans;
}

You might also like