+ 2

Whats wrong with this code?Please help!

//why error #include<stdio.h> #define greater(x,y) if(x>y) \ printf("%d is greater than %d", x,y);\ else \ printf("%d is smaller than %d", x,y); int main() { greater(5,6); return 0; }

31st May 2020, 4:04 AM
Coding San
Coding San - avatar
2 Respuestas
+ 1
I don't see anyway logical or syntactic errors. The output is as expected. Obviously remember to remove the empty newlines in the "define" body, or put continuation backslashes in them. And the "else printf" is not strictly correct: x could be also equal to y, not just smaller !
31st May 2020, 4:39 AM
Bilbo Baggins
Bilbo Baggins - avatar
+ 1
Coding Gl #include<stdio.h> #define greater(x,y) if(x>y) printf("%d is greater than %d", x,y);\ else printf("%d is smaller than %d", x,y); int main() { greater(5,6); return 0; }
31st May 2020, 9:28 AM
ogoxu
ogoxu - avatar