Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int subtraction(int num1, int num2) {
- int num2_inverted = ~num2; // invert num2 variable
- int twos_complement_of_num2 = num2_inverted + 1; // create variable of which
- // value is twos complement of num2
- return twos_complement_of_num2 + num1; // add twos complement of num2 and num1
- }
- int main() {
- printf("%d", subtraction(10, 5)); // print 10 - 5
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement