Exemple #1
0
main()
{
      double inp;
      int n,j,ans=0,lim=4;
      i=q=div=0;
      printf("Enter the number:\n");
      scanf("%lf",&inp);
      printf("input=%f\n",inp);
      n=(int)inp;
      printf("Integral part=%d\n",n);
      i=nodig(n);//checking no of digits
      //modifying initial checkings        
      if(i%2==0)
         {lim=10;i=i-2;}
      else i=i-1;  
      
        
      for(j=1;j<=lim;j++)
           if((j*j)>(n/powr(10,i)))
               {j-=1;ans=j;
                 q=(2*j); div=(n/powr(10,i)-j*j);
                ans=root(ans,n%powr(10,i));
                break;}
            
     n=(int)((inp-n)*powr(10,8));printf("floating part %lf n=%d\n",(inp-n),n);
     printf("The square root of %f is %d.",inp,ans);ans=0;
     if(div!=0){i=16;ans=root(ans,n);}
     
     lim=nodig(ans);
     
     for(j=1;j<=(8-lim);j++) printf("0");
     printf("%d\n",ans);  
}//end of main()                       
Exemple #2
0
double ObviousMethod::getAccurateValue(double x, double t)
{
    double value;
    double returnableValue;
    double x1,x2,x3;
    double expression = _accurateB-(8.0*_equationA*t);
    x1=1.0/expression;
    x2=powr(expression,-1.0/4.0);
    x3=expression*(_equationB/(15.0*_equationA));
    value = x1*x*x+_accurateA*x2-x3;
    //returnableValue = value*sqrt(fabs(value));
    returnableValue = powr(value,3.0/2.0);
    return returnableValue;
}
Exemple #3
0
int root(int ans,int n)
{    int r;
     if(i>0){
     i=i-2;div=div*100+((n>0)?(n/powr(10,i)):0);
     for(r=1;r<=10;r++)
         if(((q*10+r)*r)>div) 
             break;
     r=r-1;
     ans=ans*10+r;
     q=q*10+2*r;
     div=div-(q-r)*r;
     n=((n>0)?(n%powr(10,i)):0);
     return root(ans,n);}//end of if
     else return ans; 
}//end of root
void main()
{
	int x = 3, y = 4;

	int p = powr(x, y);
	printf("%d\n", p);
}
int powr(int x, int y)
{
	if (y == 0)
		return 1;

	return mult(x, powr(x, y-1));
}
Exemple #6
0
//function definitions
int nodig(int n)
{    int j;
     for(;1;j++)
        if((n/powr(10,j))==0)
           break;
      return j;
}// end of nodig()              
Exemple #7
0
int main(int argc, char const *argv[])
{
	int (*p)[POWER];
	int line = 10;
	int i, t, k;

	p = malloc (40 * sizeof(int));

	if(!p)
	{
		printf("the memory request is failed.\n");
		exit (-1);
	}

	for (i = 0; i < line; ++i)
	{
		for (t = 0; t < POWER; ++t)
			*(*(p+i)+t) = powr(i, t);
	}

	for (i = 0; i < line; ++i)
	{
		printf("the number %d's power are\n", i );
		for (t = 0; t < POWER; ++t)
			printf("%d  \n", *(*(p+i)+t));
	}
	return 0;
}
Exemple #8
0
ll powr(ll x,ll y,ll mod){
    if(y==1) return x;
    ll u=(x*x)%mod;
    u=powr(u,y/2,mod);
    if(y&1) u=(u*x)%mod;
    return u;
}
Exemple #9
0
			__kernel void forward(
				const __global float* input, const int input_offset,
				__global float* output, const int output_offset,
				const float alpha, const float beta,
				const __global float* local_mean,
				const __global float* local_variance)
			{
				const int i = get_global_id(0);
				output[i] = input[i]/powr(1.f+alpha*local_variance[i], beta);
			}
/*******************************************************
 * Replaces the math.h pwr function since we cannot
 * successfully link to it with the ESP8266 Arduino IDE
 *******************************************************/
float powr(float x, int y)
{
    float temp;
    if( y == 0)
       return 1;
    temp = powr(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
    {
        if(y > 0)
            return x*temp*temp;
        else
            return (temp*temp)/x;
    }
}
Exemple #11
0
int main()
{
    int a,t;
    long int b;
    scanf("%d",&t);
    while(t--)
    {
    scanf("%d%ld",&a,&b);
    int p=b%4;
    if(b&&p==0)
    p=4;
    //printf("%d\n\n",p);
    //printf("%d\n",(int)powr(a,p));
    printf("%d\n",powr(a,p)%10);
    }
    return 0;
}
Exemple #12
0
int isprime(ll p){
    if(p<2) return 0;
    if(p==2||p==3) return 1;
    if(p!=2 && p%2==0) return 0;
    ll s=p-1;
    while(s%2==0) s/=2;
    int cnt=0;
    ll a=20; 
    while(cnt++<10){
    a=f(f(a,s),s);
    ll temp=s;
    ll mod=powr(a,temp,p);
    while(temp!=p-1 && mod!=1 && mod!=p-1){
        mod=(mod*mod)%p;
        temp=temp*2;
    }
    if(mod!=p-1 && temp%2==0) return 0;
    }
    return 1;
}
Exemple #13
0
void DrawSierpIt(float a, float ax, float ay, int st)
{	//a - bok kwadratu, 
	//(ax, ay) wspolrzêdne lewego,górnego wierzcho³ka
	DrawRect(a,ax,ay);
	for(int i=0; i<st; i++)
	{

		int pow = powr(i);
		float x = a/(1.0*(pow));

		for(int j=0; j<pow; j++)
		{
			for(int k=0; k<pow; k++)
			{
				float na = a/(3*pow); //bok kwadratu wycinanego w danym stopniu trójk¹ta
				float nx = ax + (k * x) + (a/(3*pow)); // wsp³. wyciannaego kwadratu
				float ny = ay - ((j * x) + (a/(3*pow)));
				DrawBlack(na, nx, ny); // rysowanie czarnego kwadratu
			}
		}
		
	}
}
// Converts a floating point number to string.
void ftoa(float n, char *res, int afterpoint)
{
    // Extract integer part
    int ipart = (int)n;

    // Extract floating part
    float fpart = n - (float)ipart;

    // convert integer part to string
    int i = intToStr(ipart, res, 0);

    // check for display option after point
    if (afterpoint != 0)
    {
        res[i] = '.';  // add dot

        // Get the value of fraction part upto given no.
        // of points after dot. The third parameter is needed
        // to handle cases like 233.007
        fpart = fpart * powr(10, afterpoint);

        intToStr((int)fpart, res + i + 1, afterpoint);
    }
}
Exemple #15
0
Fichier : sa.c Projet : drigz/5R1
real randf()
{
    return random() / powr(2, 31) + 1 / powr(2, 32);
}
Exemple #16
0
void ObviousMethod::calculateMethod(double a, double b, double A, double B)
{
    setEquationA(a);
    setEquationB(b);
    setAccurateA(A);
    setAccurateB(B);
    double XR;
    double TR;
    int i,j,k;
    int n=numberOfX;
    QVector< QVector<double> > testValue;
    QVector<double> helpVector(numberOfX);
    testValue.push_back(helpVector);
    double left;
    double right;
    double *Accurate = new double [numberOfT*numberOfX];
    double maxAbs,maxVidn;
    double x1,x2,x3,x4,x5,x6;
    for(XR=0,i=0;i<numberOfX;i++,XR+=_h)
    {
        X[i]=XR;
    }
    for(TR=0,j=0;j<numberOfT;j++,TR+=_thau)
    {
        T[j]=TR;
    }
    for(i=0;i<numberOfX;i++)
    {
        W[i]=getAccurateValue(X[i],0);
    }

    for(k=0;k<numberOfT;k++)
    {

        for(i=0;i<numberOfX;i++)
        {
            Accurate[k*n+i]=getAccurateValue(X[i],T[k]);
            testValue[0][i]=Accurate[i];
        }
    }
    for(k=1;k<numberOfT;k++)
    {
        testValue.push_back(helpVector);
        //stream << endl;
        left = getLeftBoundaryCondition(T[k]);
        right = getRightBoundaryCondition(T[k]);
        W[k*n]=left;//stream << W[k*n] << " ";
        W[k*n+n-1]=right;
        testValue[k][0]=W[k*n];
        testValue[k][n-1]=W[k*n+n-1];
        for(i=1;i<numberOfX-1;i++)
        {
            x1=powr(W[(k-1)*n+i],-1.0/3.0);
            x2=powr(((W[(k-1)*n+i+1]-W[(k-1)*n+i-1])/(2*_h)),-1.0/3.0);
            x3=powr(W[(k-1)*n+i],2.0/3.0);
            double test1,test2,test3,test4,test5,test6;
            test1=W[(k-1)*n+i-1];
            test2=W[(k-1)*n+i];
            test3=W[(k-1)*n+i+1];
            test6=2*test2;
            test4=(test1-test6+test3)/(_h*_h);
            x4=(W[(k-1)*n+i-1] - 2*W[(k-1)*n+i] + W[(k-1)*n+i+1])/(_h*_h); // change formula
            x5=powr(W[(k-1)*n+i],1.0/3.0);
            x6=W[(k-1)*n+i];
            test5=_thau*_equationA*((2.0/3.0*x1*x2)+(x3*x4))+_thau*_equationB*x5+x6;
            W[k*n+i]=_thau*_equationA*((2.0/3.0*x1*x2)+(x3*x4))+_thau*_equationB*x5+x6;
            testValue[k][i]=W[k*n+i];
           //stream << W[k*n+i] << " ";
        }
        //stream << W[k*n+4]<<" ";
        for(i=0;i<numberOfX;i++)
        {
            stream << qSetFieldWidth(15)<< "time is " << T[k] << " yApp " << W[k*n+i] << " yAcc " << Accurate[k*n+i] << "      absPoh" << fabs(W[k*n+i]-Accurate[k*n+i])<< "      otnPoh=  "<< fabs((W[k*n+i]-Accurate[k*n+i])/W[k*n+i]*100.)<<endl;
            graph << X[i] << " " << T[k] << " " << W[k*n+i] << endl;
            logObvious << W[k*n+i] << "     " << Accurate[k*n+i]<< "     " << fabs(W[k*n+i]-Accurate[k*n+i])*0.01<< "     "<< fabs((W[k*n+i]-Accurate[k*n+i])/W[k*n+i]*100.)*0.01<< endl;
        }
        stream<<endl;
        logObvious<<endl;
    }
    maxAbs=fabs(W[0]-Accurate[0]);
    maxVidn=fabs((W[0]-Accurate[0])/Accurate[0]*100.0);
    for(k=0;k<numberOfT;k++)
    {
        //stream<<endl;
        for(i=0;i<numberOfX;i++)
        {
            if(fabs(W[k*n+i]-Accurate[k*n+i]) > maxAbs) maxAbs =fabs(W[k*n+i]-Accurate[k*n+i]);
            if(fabs((W[k*n+i]-Accurate[k*n+i])/Accurate[k*n+i]*100)>maxVidn) maxVidn =fabs((W[k*n+i]-Accurate[k*n+i])/Accurate[k*n+i]*100);
            //stream << fabs(W[k*n+i] - Accurate[k*n+i]) << "       " ;
        }
    }
    stream << maxAbs<< "  " << maxVidn;
    fout << a << " "<< b<< " "<<A<< " "<< B<< "            "<< maxAbs << "          " << maxVidn << endl;
    stream.flush();
}