Search This Blog

C Program for Subtraction Without Using Minus Sign

The following is a program to subtract a number from another without using minus symbol. Instead of doing a normal subtract operation, the two's complement of the subtrahend is added to the minuend. (In 3-4, 3 is minuend and 4 is subtrahend.) In other words, the 1's complement and 1 is added to minuend.

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


No comments: