#include <stdio.h>
#define zero 0.000001

double mypow(double x,int n)
{
	if(n==0) return 1.0;
	double t=1.0;
	for(;n>0;t*=x,n--);
	return t;
}

int searchroot(double x,int n)
{
	int t=1;
	while(1)
	{
		if (mypow(t,n)-x<=zero && mypow(t+1,n)-x>=zero) return t;
		t++;
	}
	return t;
}
double myfabs(double m,double n)
{
    double t=m-n;
    if(t>0) return t;else return t*(-1);
}
double rooting(double x,int n)
{
    int root=searchroot(x,n);
    double x1=(double)root;
    double x0,f0,f1;
    do
    {
        x0=x1;
        f0=mypow(x0,n)-x;
        f1=n*mypow(x0,n-1);
        x1=x0-f0/f1;
    }while(myfabs(x0,x1)>=zero);
    return x1;
}
int main()
{
    double x=88888888;
    int n=2;
    for(;n<8;printf("对%12.0f进行开%d次方结果是%12.6f\n",x,n,rooting(x,n),n++));
    n=2;
    for(;n<8;printf("验证%12.6f的%d次方=%12.6f\n",rooting(x,n),n,mypow(rooting(x,n),n),n++));
   	return 0;
}