AlexandruT

Ridicare la putere in timp logaritmic

Jan 21st, 2015
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.27 KB | None | 0 0
  1. int Putere(int baza, int exp)
  2. {
  3.     put = 1;
  4.     while(exp)
  5.     {
  6.         if(exp % 2 == 1)
  7.         {
  8.             put *= baza;
  9.             exp--;
  10.         }
  11.         else
  12.         {
  13.             exp /= 2;
  14.             baza *= baza;
  15.         }
  16.     }
  17.     return put;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment