R
Richard said:Bart C said:
No, the use of +
Hi,
Can anyone please give me a hint/logic to divide a number with any
number without using '/' '+' '*' '-'.
Thank You.
Regards,
New
spaglia said:I think this will do it. It handles unsigned operands and /0 is
not special cased (assumes 32-bit integers):
The use of "--" or "++" involves the use of '-' or '+'. At any
rate, why spend time on such a foolish project?
CBFalconer said:The use of "--" or "++" involves the use of '-' or '+'.
At any rate, why spend time on such a foolish project?
luvraghu said:Hi,
Can anyone please give me a hint/logic to divide a number with any
number without using '/' '+' '*' '-'.
You can't use - or *, either.user923005 said:Here are some other ways to divide without using division that are
equally horrible:
#include <stdio.h>
#include <math.h>
#include <float.h>
int double_compare(double d1, double d2)
{
if (d1 > d2)
if ((d1 - d2) < fabs(d1 * DBL_EPSILON))
or even... copysign(1, EOF)Army1987 said:For integers:
#include <stdlib.h>
...
int result;
div_t q;
q = div(numer, denom);
result = q.quot;
For floating point (C99 only):
#include <math.h>
#include <limits.h>
result = fma(numer, pow(denom, copysign(1, cos(3)), 0);
In my case (newish to C) it's a useful exercise.
Chris Dollin said:I think there are /many/ other things about C that would
make more useful initial exercises than re-implementing
arithmetic.
Do you not?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.