#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) {
Here is the algorithm that works well and takes O(log n) time.
Algorithm Exponientiate(x n) //computes x^n for an integer n> 0 { m: n; power: 1; z: x; while( ( m mod 2 ) 0 ) do { m: m/2 ; //take the floor of the result. z: z^2; //square of z