Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int subtraction(int num1, int num2) {
  4. int num2_inverted = ~num2; // invert num2 variable
  5. int twos_complement_of_num2 = num2_inverted + 1; // create variable of which
  6. // value is twos complement of num2
  7. return twos_complement_of_num2 + num1; // add twos complement of num2 and num1
  8. }
  9.  
  10. int main() {
  11. printf("%d", subtraction(10, 5)); // print 10 - 5
  12. return 0;
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement