I faced an interview. where I was asked the following question
Write a function in any of programming language that computes the nth power of a number w/o using + * or ^ or declaring a new variable inside the function or using any library function (eg Math lib in java).
I have used pow function of java Math.pow(a, b)
Thanks
I am using java programming language. The interviewer restricted you to declare a new variable inside the method better you pass it to the function. The interviewer didnt restrict you to use division operator (/) so you can use that.
if you want to get 5th power of a number 3 then write
System.out.println("4..double..." + getNthPowerOfNumber(4, 1));