Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • PROGRAM TO SUBTRACT TWO NUMBER WITHOUT USING SUBTRACTION OPERATOR

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 787
    Comment on it

    A program on C language without using subtraction operator is done by taking the numbers 2's complement and then add it to another number.

    #include<stdio.h>
    
    int main(){
    
        int a,b;
        int sum;
         int complement=0;
    
        printf("Enter any two integers: ");
        scanf("%d%d",&a,&b);
         complement= ~b+1;                               //2's complement of b
    
        sum = a + b; 
    
        printf("Difference of two integers: %d",sum);
    
        return 0;
    }
    

    Sample Output:

    Enter any two integers: 7 4
    Difference of two integers: 3
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: