Blogger templates

Searching...
Tuesday, March 19, 2013

Subtract two numbers without using subtraction operator

12:29 PM

How to subtract two numbers without using subtraction operator

#include <stdio.h>

int main()
{
    int num1, num2;
    int subtraction;

    printf("Enter an integer (a): ");
    scanf("%d", &num1);
    printf("Enter an integer (b): ");
    scanf("%d", &num2);
    subtraction = num1 + ~num2 + 1;
    printf("\nSubtraction of %d and %d is: %d \n", num1, num2, subtraction);
    return 0;
}

0 comments:

Post a Comment