PROGRAM TO RAISE A POWER OF A NUMBER




Hello Friends!!! Today I am going to learn program for raising a power of a number to N.Here N is any +ve number. So Let's Start=>

//Name : Mayank Sharma //
//Roll No : 1101026 //
//CSE(4th Sem)

PROGRAM TO RAISE A POWER OF A NUMBER

#include
#include
double power(int p=2, double n);
int main()
{
double n, r;
int pow;
char c;
clrscr();
cout<<"enter the number \n";
cin>>n;
do
{
cout<<"Do u Want to enter the Power (Y/N) ?";
cin>>c;
if(c=='y')
{
cout<<"enter the power to be raised ";
cin>>pow;
r=power(pow,n);
}
else
{
if(c=='n')
{
r=power(pow,n);
}
else
{
cout<<"Invalid Choice ";
}
}
while(c!='y' && c!='n')
cout< getch();
return 0;
}
double power(int p, double n)
{
double r=1;
int i;
if(p<0 data-blogger-escaped-br=""> {
r=1/power(-p,n);
}
else
{
for(i=1;i<=p;i++)
r=r*n;
}
}
return 0;
}

I think this post will help you.I think this post will help you.
Thanks!!!
If any query about this post then put your comment in comment box below..

0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites