Guest User

Russian Peasant Multiplication

a guest
Oct 25th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.69 KB | None | 0 0
  1.   1 #include <stdio.h>
  2.   2
  3.   3 int main(void)
  4.   4 {
  5.   5 int i=85,j=18,k=0;
  6.   6
  7.   7 if(i%2 == 1){
  8.   8         k += j;
  9.   9 }
  10.  10
  11.  11 while(i>1)
  12.  12 {
  13.  13 i /= 2;
  14.  14 j *=2;
  15.  15 if(i%2 == 1){
  16.  16         k += j;
  17.  17 }
  18.  18
  19.  19 }
  20.  20 printf("%d\n",k);
  21.  21 return 0;
  22.  22 }
  23. ~                                                                                                                                              
  24. ~                                                                                                                                              
  25. ~                                                                                                                                              
  26. ~                                                                                                                                              
  27. ~                                                                                                                                              
  28. ~                                                                                                                                              
  29. ~                                                                                                                                              
  30. ~                                                                                                                                              
  31. ~                                                                                                                                              
  32. ~                                                                                                                                              
  33. ~                                                                                                                                              
  34. ~                                                                                                                                              
  35. ~                                                                                                                                              
  36. ~                                                                                                                                              
  37. ~                                                                                                                                              
  38. ~                                                                                                                                              
  39. "denm.c" 22L, 169C written                                                                                                   10,0-1        All
Advertisement
Add Comment
Please, Sign In to add comment