Write a c program to subtract two numbers without using subtraction operator






Write a c program or code to subtract two numbers without using subtraction operator


#include<stdio.h>

int main(){
   
    int a,b;
    int sum;

    printf("Enter any two integers: ");
    scanf("%d%d",&a,&b);

    sum = a + ~b + 1;

    printf("Difference of two integers: %d",sum);

    return 0;
}

Sample Output:

Enter any two integers: 5 4
Difference of two integers: 1





3 comments:

  1. write a c program to display all even factors of a given number using function in c

    ReplyDelete
  2. can u give me a program in c to calculate the series 1+4+25+........+n using double loops

    ReplyDelete
  3. how is it possible solution of above example question
    sum=a+~b+1

    ReplyDelete