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



August 08, 2007 20:55:28 #7
 jinhu   Member Since: Visitor    Total Comments: N/A 

RE: write an O(log2(N)) algorithm to find X^N
 
my anwser:
int xpwrn(int x,int n)
{
    int i=0;
    int rv=1;
    int n=x;
    for(;i<32&&(1<<i)<x;++i)
    {
            if((1<<i)&x != 0)
            {
               rv *= n;
             }
             n  *=x;
    }
    return rv;
}
     

 

Back To Question