How to add two numbers without using the plus operator in c
#include <stdio.h>
int main()
{
int num1, num2;
int summation;
printf("Enter an integer (x): ");
scanf("%d", &num1);
printf("Enter an integer (y): ");
scanf("%d", &num2);
summation = num1 - ~num2 - 1;
printf("\nSummation of %d and %d is: %d \n", num1, num2, summation);
return 0;
}
#include <stdio.h>
int main()
{
int num1, num2;
int summation;
printf("Enter an integer (x): ");
scanf("%d", &num1);
printf("Enter an integer (y): ");
scanf("%d", &num2);
summation = num1 - ~num2 - 1;
printf("\nSummation of %d and %d is: %d \n", num1, num2, summation);
return 0;
}
Here is another way to do that. Just use subtract operator. For Example:
ReplyDeletesummation = num1 - (-num2) //dont need to use ~
Exactly, but when you will subtract two numbers ~ is required. Or you have to use << Shifting operator.
Delete