double pow1(double x, int n) { if(x == 0 || x == 1 || n == 1) return x; if(n == 0){ return 1.0; } if(n < 0){ if (n == -2147483648) { n = n - 2; } else {n = (-1) * n;} return 1 / pow1(x,n); } if(n % 2 == 0){ if (x < 0) { x = (-1) * x; } double half = pow1(x, n / 2); return half * half; } else{ double half = pow1(x, n / 2); return half * half * x; } }
int MaxProduct() { int min = pow1(10,DIGITS-1); int max = 0; int i = 0; int num1 = 0, num2 = 0; int maxProduct = 0; for(i=0; i<DIGITS; i++) { max = max*10 + 9; } for(num1=max; num1 >= min; num1--) { for(num2=num1-1; num2 >= min; num2--) { if(IsPalindrome(num1*num2)) { maxProduct = maxProduct < num1*num2 ? num1*num2 : maxProduct; } } } return maxProduct; }
int main(void) { double user_base; int user_power; double func_result; printf("\nGive me a base : "); scanf("%lf", &user_base); printf("Give me a power : "); scanf("%d", &user_power); printf("\nMethod 1: Strict Recursion, No Halving\n"); func_result = pow1(user_base, user_power); printf(" Result: %.2lf in %d steps\n", func_result, max); pow1_max = max; max = count = 0; printf("\nMethod 2: Recursion with Halving\n"); func_result = pow2(user_base, user_power); printf(" Result: %.2lf in %d steps\n\n", func_result, max); printf("Recursion with halving took %.2lf percent less calculations.\n", ( ((double) (pow1_max) / max )*100)); return 1; }
float term (int x, int k) { int pow,fac; pow=pow1(x,k); fac=fact(k); return (float)pow/(float)fac; }
double pow1(double base, int power) { determining(base, power, 1); if (power == 0) return 1; if (power > 0) { if (power == 1) { result = base; } else { result = base * pow1(base, power-1); } } else { result = 1 / pow1(base, power * -1); } determined(base, power, -1, result); return result; }
int pow1(int x, int n) { if (n == 1) return x; else { int c = pow1(x, n/2); if (n & 1) return c*c*x; else return c*c; } }
int main (int argc, char ** argv) { unsigned i,j, p; for (j = 0; j < 100; ++j) { for (i = 0; i < 1000000; ++i) { p = pow1(i); //printf("%u: %u\n", i, pow1(i)); } } return 0; }
// Function to convert binary to decimal. int binary_decimal(int n[7]) { int i=0, rem ,decimal=0; int j=6; i=0; while (j>=0) { decimal += n[j]*pow1(2,i); --j; ++i; } return decimal; }
int main() { int i,x,N; float Sum=0.0; printf("Enter x and N\n"); scanf("%d %d",&x,&N); if(N>=0) { for(i=0;i<=N;i++) Sum=Sum+pow1(-1,i)*term(x,i); printf("The Sum = %f\n",Sum); } else printf("Wrong N value\n"); return 0; }
int main(void) { char c[10]; int n[10],l; int i; int ans=0 ; while(fgets(c,10,stdin)!=0){ l=strlen(c)-1; for(i=0;i<l;i++){ n[i]=c[i]-64; } for(i=0;i<l;i++){ ans= ans + (n[i])*pow1(26,l-i-1); } printf("%d\n",ans); ans=0; } }
int main(int argc, const char* argv[]) { cout << pow1(3, 4) << endl; return 0; }
main(int argc,char **argv) { char s[10]; int n,n1,vm,ps,loc; FILE *fp; struct st v[5]; fp=fopen("input.c","r"); if(fp==NULL) { printf("FIle not present...\n"); return; } int i=0,page[5],j=0,k=0; int c[5]={0,0,0,0,0},aa[10]; char m[6][20]; n=atoi(argv[1]); vm=pow1(n); n1=atoi(argv[2]); ps=pow1(n1); printf("vm=%d ps=%d\n",vm,ps); printf("No of pages are:%d\n",vm/ps); loc=atoi(argv[3]); for(i=0;i<6;i++) bzero(m[i],20); i=0; while(fscanf(fp,"%s",s)!=EOF) { if(i%2==0) { int tmp; tmp=atoi(s); v[j].page[j]=tmp/ps; //printf("%d in %d page..\n",tmp,page); // for(j=0;j<loc;j++) if(j<5) { aa[j]=v[j].page[j]; v[j].tmp[j]=3; printf("page NULL replaced by %d=%d..\n",v[j].page[j],v[j].tmp[j]); /*if(c==4) { v[j].tmp[j]--; printf("v.tmp=%d\n",v[j].tmp[j]); } c++;*/ } else { int t; // goto aaa; static int y=0; t=v[j].page[j];//save j>5 page int t // printf("t=======%d\n",t); if(c[y]==4) { v[y].tmp[y]--; y++; } else { c[y]++; } if(v[y].tmp[y]==0) { printf("page %d replaced by %d\n",v[y].page[y],t); } k++; } j++; } else { static int l=0; static int v1=0; if(l<5){ strcpy(m[l],s); printf("Dummy %d -- %s\n",l,m[l]); } for(i=0;i<5;i++) printf("%s\n",m[i]); // aa[l]=v[l].page[l]; // printf("%s %d\n",s,aa[l]); if(j>5) { if(v1<5) { printf("m[%d]== %s \n",v1,m[v1]); if(strcmp(m[v1],"w")==0) printf("page %d is dirty page..\n",aa[v1]); else printf("page %d is not dirty page..\n",aa[v1]); v1++; } } // printf("Dummy %d -- %s\n",l,m[l]); l++; } i++; } }
double t = 1; //To Handle -ve power cases if (n < 0 ) { n = -n ; x = 1/x;} //Base case if (n == 0) { return t ;} //store output if ( true == is_even (n) ) { t = pow(x,n/2); t = t*t; }else { t = x * pow(x,n-1); } return t; } //optimized version with same complexity as pow(); double pow1(const double base,int n) { if(n == 0) return 1; double ret; else if(n%2 == 0) { ret = pow1(base,n/2); return ret * ret; }else { ret = pow1(base,(n-1)/2); return base * ret * ret; } } };
int main(void) { printf("%d\n",pow1(2,1000)); }
void Result::showResultWin(int score){ int left = -320; int right = 320; int top = 240; int bot = -240; char strbuffer[64]; // W Point pow1(left+60,top-80); Point pow2(left+140+5,bot+220); Point pow3(left+180+5,bot+300); Point pow4(left+220+5,bot+220); Point pow5(left+300+10,top-80); Point pow6(left+260+5,top-80); Point pow7(left+220+5,top-160); Point pow8(left+180+5,top-80); Point pow9(left+140+5,top-160); Point pow10(left+100+5,top-80); Point powc((pow1.x+pow5.x)/2,(pow1.y+pow2.y)/2); vector<Point> pow; pow.push_back(pow1); pow.push_back(pow2); pow.push_back(pow3); pow.push_back(pow4); pow.push_back(pow5); pow.push_back(pow6); pow.push_back(pow7); pow.push_back(pow8); pow.push_back(pow9); pow.push_back(pow10); if (firsttime){ pol_w.setCorner(pow); pol_w.setCenter(powc); Transform scale = createScale(0.1, 0.1); pol_w.applyTransform(scale); } // I Point poi1(left+340,top-80); Point poi2(left+340,bot+220); Point poi3(left+390,bot+220); Point poi4(left+390,top-80); Point poic((poi1.x+poi3.x)/2,(poi1.y+poi3.y)/2); vector<Point> poi; poi.push_back(poi1); poi.push_back(poi2); poi.push_back(poi3); poi.push_back(poi4); if (firsttime){ pol_i.setCorner(poi); pol_i.setCenter(poic); Transform scale = createScale(0.1, 0.1); pol_i.applyTransform(scale); } // N Point pon1(left+420,top-80); Point pon2(left+420,bot+220); Point pon3(left+470,bot+220); Point pon4(left+470,top-170); Point pon5(left+530,bot+220); Point pon6(left+580,bot+220); Point pon7(left+580,top-80); Point pon8(left+530,top-80); Point pon9(left+530,bot+310); Point pon10(left+470,top-80); Point ponc((pon1.x+pon6.x)/2,(pon1.y+pon6.y)/2); vector<Point> pon; pon.push_back(pon1); pon.push_back(pon2); pon.push_back(pon3); pon.push_back(pon4); pon.push_back(pon5); pon.push_back(pon6); pon.push_back(pon7); pon.push_back(pon8); pon.push_back(pon9); pon.push_back(pon10); if (firsttime){ pol_n.setCorner(pon); pol_n.setCenter(ponc); Transform scale = createScale(0.1, 0.1); pol_n.applyTransform(scale); } // Other Point pot1(left+60, top-40); Point pot2(right-60, top-40); Point pot3(right-60, top-60); Point pot4(left+60, top-60); Point potc((pot1.x+pot2.x)/2,(pot2.x+pot3.x)/2); vector<Point> pot; pot.push_back(pot1); pot.push_back(pot2); pot.push_back(pot3); pot.push_back(pot4); if (firsttime){ pol_pot1.setCorner(pot); pol_pot1.setCenter(potc); Transform scale = createScale(0.1, 0.1); pol_pot1.applyTransform(scale); } pot1.set(left+60, bot+180); pot2.set(right-60, bot+180); pot3.set(right-60, bot+200); pot4.set(left+60, bot+200); potc.set((pot1.x+pot2.x)/2,(pot2.x+pot3.x)/2); pot.clear(); pot.push_back(pot1); pot.push_back(pot2); pot.push_back(pot3); pot.push_back(pot4); if (firsttime){ pol_pot2.setCorner(pot); pol_pot2.setCenter(potc); Transform scale = createScale(0.1, 0.1); pol_pot2.applyTransform(scale); } resultframe++; if (resultframe >= 25) resultframe = 25; else { Transform scale = createScale(1.1, 1.1); pol_pot1.applyTransform(scale); pol_pot2.applyTransform(scale); pol_w.applyTransform(scale); pol_i.applyTransform(scale); pol_n.applyTransform(scale); } pol_w.draw(WHITE); fill_polygon(pol_w[0].x, pol_w[3].y, pol_w[4].x, pol_w[0].y,WHITE,WHITE); pol_i.draw(WHITE); fill_polygon(pol_i[0].x, pol_i[2].y, pol_i[2].x, pol_i[0].y,WHITE,WHITE); pol_n.draw(WHITE); fill_polygon(pol_n[0].x, pol_n[5].y, pol_n[5].x, pol_n[0].y,WHITE,WHITE); pol_pot1.draw(WHITE); pol_pot2.draw(WHITE); settextstyle(7,0,40); setcolor(WHITE); sprintf(strbuffer,"%d",score); outtextxy(getmaxx()/2-50, getmaxy()/2+100, strbuffer); firsttime = false; }
int main() { int x, n; scanf("%d%d", &x, &n); printf("%d %d\n", pow1(x, n), pow2(x, n)); return 0; }
double solve(ll n) { double a=(1+sqrtl(5))/2,b=(1-sqrtl(5))/2; return (pow1(a,n)-pow1(b,n))/(a-b); }