Advertisement
tm512

Untitled

Jul 21st, 2011
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.36 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int add (int a, int b)
  4. {
  5.     int c = b & a;
  6.  
  7.     while (a)
  8.     {
  9.         c = b & a;
  10.         b = b ^ a;
  11.         c <<= 1;
  12.         a = c;
  13.     }
  14.  
  15.     return b;
  16. }
  17.  
  18. int main (void)
  19. {
  20.     printf ("1 + 1 is %i.\n", add(1, 1));
  21.     printf ("2 + 2 is %i.\n", add(2, 2));
  22.     printf ("4 + 7 is %i.\n", add(4, 7));
  23.  
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement