I answered a question on SO today, however it did't receive any up-votes, so I want to know what's wrong with my code.
The requirement is to compare the input numbers(granted to be positive) without logical, relational or bitwise operators, and insert the corresponding comparison sign between them. For example:
input: 4 6
output: 4 < 6
input: 10 2
output: 10 > 2
input: 2 2
output: 2 = 2
Here is my posted code:
#include <stdio.h>
int main(void)
{
unsigned a, b;
scanf("%u %u", &a, &b);
printf("%u ", a);
char relationship[] = {'<', '=', '>'};
putchar(relationship[!!(a/b) - !!(b/a) + 1]);
printf(" %u", b);
return 0;
}
That OP wants to know how to insert a comparison sign(<
, >
, =
) between the two numbers. But my emphasis is on how to determine the relationship of the two numbers.
See: https://stackoverflow.com/q/35532123/5399734 for the original question.
!
considered a logical operator? \$\endgroup\$!
operators. See my posted code on SO: stackoverflow.com/a/35533732/5399734 \$\endgroup\$