fork(2) download
  1. #include <stdio.h>
  2.  
  3. int exponent_fast(int x,int n)
  4. {
  5. int result=1,m,sample=x;
  6. m=n;
  7. while(m>0)
  8. {
  9. while( m%2 == 0)
  10. {
  11. sample =sample *sample;
  12. m/=2;
  13. if(m==0)break;
  14. }
  15. --m;
  16. result = result * sample;
  17. }
  18. return result;
  19. }
  20. int main(void) {
  21. // your code goes here
  22. printf("%d\n",exponent_fast(2,4));
  23. printf("%d\n",exponent_fast(2,3));
  24. printf("%d\n",exponent_fast(3,4));
  25. printf("%d\n",exponent_fast(3,3));
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0s 2292KB
stdin
Standard input is empty
stdout
16
8
81
27