Created
January 15, 2023 07:52
-
-
Save tsutsui/2d52ddc65e22711332fb89d1d2c8de42 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| int cmp(double d1, double d2) | |
| { | |
| if (d1 == d2) return 0; | |
| else if (d1 - d2 < 0) return -1; | |
| else return 1; | |
| } | |
| int main() | |
| { | |
| int ret, exp; | |
| double d1, d2; | |
| d1 = 3.0; d2 = 3.0; exp = 0; ret = cmp(d1, d2); | |
| if (exp != ret) | |
| printf(" wrong result d1: %f d2: %f exp: %d ret: %d\n", d1, d2, exp, ret); | |
| d1 = 0.0; d2 = 3.0; exp = -1; ret = cmp(d1, d2); | |
| if (exp != ret) | |
| printf(" wrong result d1: %f d2: %f exp: %d ret: %d\n", d1, d2, exp, ret); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment