/*
Program to find difference of two integers without using - operator
Programmer : Syed Mohammad Ali
*/
#include<stdio.h>
void main()
{
int a,b,diff=0;
printf("Enter two integers\n");
scanf("%d%d",&a,&b);
if(a!=b)
{
while(a!=b)
{
diff++;
b++;
}
}
else
{
}
printf("Difference = %d\n",diff);
}
/*
The Basic idea here is we assume we don't have - operator in our language.
Increment the small value variable until its value becomes equal to other variable value. Simultaneously increment the counter variable. When both variables values are equal, counter will hold the difference of the two numbers.
In the above program diff is the counter variable.
*/
No comments:
Post a Comment