GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Placement Papers  >  Adobe  >  Placement Papers

 Print  |  
Question:  write an O(log2(N)) algorithm to find X^N



May 05, 2006 07:18:39 #3
 deepak kumar   Member Since: Visitor    Total Comments: N/A 

RE: write an O(log2(N)) algorithm to find X^N
 
#include#includelong int a;long int func(long int x,long int n);int s=1;void main(){ long int x,n,p=1; scanf("%li",&x); for (n=2;n<15;n++) { a=x; s=1; if (n%2==1) p=func(x,n-1)*x; else p=func(x,n); printf("\n%li %li = %li",x,n,p*s); } getch();}long int func(long int x,long int n){ if (n==1) return x; if (n%2==1) {
     

 

Back To Question