0
Was is the reason for this strange behavior?
2 Antworten
+ 2
Use parenthesis:
#define prod(i, j) (i) * (j)
Otherwise, you'll get this as output:
prod(x-1, y)
== x-1*y == 11-5 == 6.
prod(x+1, y)
== x+1*y == 11+5 == 16.
prod(x, y-1)
== x*y-1 == 55-1 == 54.
prod(x, y+1)
== x*y+1 == 55+1 == 56.
prod(x-1, y-1)
== x-1*y-1 == 11-5-1 == 5.
prod(x+1, y+1)
== x+1*y+1 == 11+5+1 == 17.
+ 2
Thanks for the answers. Now i understand the rules.