Interviewer And Interviewee Guide

Programming Concepts Interview Question:

Write an O(log2(N)) algorithm to find X^N?

Submitted by: Administrator
int computeXn(int x, int n)

{

if(n == 2)

{

return x*x;

}

else if(n % 2 == 0)

{

int y = computeXn(x, n/2);

return y*y;

}

else if(n % 2 == 1)

{

int y = computeXn(x, n/2);

return y*y*x;

}

}
Submitted by: Administrator

Read Online Programming Concepts Job Interview Questions And Answers
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.