#include"stdio.h"
double Powerfun(double MiddleDou,int PowerInt)
{
double ResultDou=1;
for(;PowerInt>0;PowerInt--)
{
ResultDou*=MiddleDou;
}
return ResultDou;
}
double BigerFun(double NumDou,int PowerInt)
{
double SmallerDou=0,BigerDou=NumDou,MiddleDou,CompareDou;
for(;;)
{
MiddleDou=(SmallerDou+BigerDou)/2;
CompareDou=Powerfun(MiddleDou,PowerInt)-NumDou;
if(CompareDou>0)BigerDou=MiddleDou;
else {SmallerDou=MiddleDou;CompareDou=-CompareDou;}
if(CompareDou<10e-15)break;
}
return MiddleDou;
}
double SmallerFun(double NumDou,int PowerInt)
{
double SmallerDou=NumDou,BigerDou=NumDou,MiddleDou,CompareDou;
for(;;)
{
BigerDou*=2;
if(Powerfun(BigerDou,PowerInt)-NumDou>=0)break;
}
for(;;)
{
MiddleDou=(SmallerDou+BigerDou)/2;
CompareDou=Powerfun(MiddleDou,PowerInt)-NumDou;
if(CompareDou>0)BigerDou=MiddleDou;
else {SmallerDou=MiddleDou;CompareDou=-CompareDou;}
if(CompareDou<10e-15)break;
}
return MiddleDou;
}
void main()
{
float NumDou;
int PowerInt;
printf("please input a number and radicel number/n");
scanf("%f%d",&NumDou,&PowerInt);
if(NumDou>1)printf("The result is %f/n",BigerFun(NumDou,PowerInt));
else if(NumDou==1)printf("The result is %f/n",1.0);
else if(NumDou>=0)printf("The result is %f/n",SmallerFun(NumDou,PowerInt));
else if(PowerInt!=PowerInt/2*2)
{
NumDou=-NumDou;
if(NumDou>1)printf("The result is %f/n",-BigerFun(NumDou,PowerInt));
else if(NumDou==1)printf("The result is %f/n",-1.0);
else if(NumDou>=0)printf("The result is %f/n",-SmallerFun(NumDou,PowerInt));
}
else printf("Sorry your numbers maybe wrong!/n");
}
double Powerfun(double MiddleDou,int PowerInt)
{
double ResultDou=1;
for(;PowerInt>0;PowerInt--)
{
ResultDou*=MiddleDou;
}
return ResultDou;
}
double BigerFun(double NumDou,int PowerInt)
{
double SmallerDou=0,BigerDou=NumDou,MiddleDou,CompareDou;
for(;;)
{
MiddleDou=(SmallerDou+BigerDou)/2;
CompareDou=Powerfun(MiddleDou,PowerInt)-NumDou;
if(CompareDou>0)BigerDou=MiddleDou;
else {SmallerDou=MiddleDou;CompareDou=-CompareDou;}
if(CompareDou<10e-15)break;
}
return MiddleDou;
}
double SmallerFun(double NumDou,int PowerInt)
{
double SmallerDou=NumDou,BigerDou=NumDou,MiddleDou,CompareDou;
for(;;)
{
BigerDou*=2;
if(Powerfun(BigerDou,PowerInt)-NumDou>=0)break;
}
for(;;)
{
MiddleDou=(SmallerDou+BigerDou)/2;
CompareDou=Powerfun(MiddleDou,PowerInt)-NumDou;
if(CompareDou>0)BigerDou=MiddleDou;
else {SmallerDou=MiddleDou;CompareDou=-CompareDou;}
if(CompareDou<10e-15)break;
}
return MiddleDou;
}
void main()
{
float NumDou;
int PowerInt;
printf("please input a number and radicel number/n");
scanf("%f%d",&NumDou,&PowerInt);
if(NumDou>1)printf("The result is %f/n",BigerFun(NumDou,PowerInt));
else if(NumDou==1)printf("The result is %f/n",1.0);
else if(NumDou>=0)printf("The result is %f/n",SmallerFun(NumDou,PowerInt));
else if(PowerInt!=PowerInt/2*2)
{
NumDou=-NumDou;
if(NumDou>1)printf("The result is %f/n",-BigerFun(NumDou,PowerInt));
else if(NumDou==1)printf("The result is %f/n",-1.0);
else if(NumDou>=0)printf("The result is %f/n",-SmallerFun(NumDou,PowerInt));
}
else printf("Sorry your numbers maybe wrong!/n");
}