diff --git a/source/_drafts/answer3.md b/source/_posts/answer3.md similarity index 91% rename from source/_drafts/answer3.md rename to source/_posts/answer3.md index aa38b28..eeb7780 100644 --- a/source/_drafts/answer3.md +++ b/source/_posts/answer3.md @@ -1,8 +1,10 @@ --- title: 第三次作业(答案) +date: 2020-10-30 15:53:35 tags: --- + # P108-3 写出下面各逻辑表达式的值。设`a = 3`,`b = 4`,`c = 5`。 @@ -133,14 +135,11 @@ int main() ```C #include #include +#include int main() { double r2 = 1; - double ax = 2, ay = 2, - bx = -2, by = 2, - cx = -2, cy = -2, - dx = 2, dy = -2; double x, y; printf("请分别输入所在位置的的x、y坐标:\nx = "); if (scanf("%lf", &x) != 1) { @@ -152,12 +151,11 @@ int main() fprintf(stderr, "非法输入!\n"); exit(EXIT_FAILURE); } - double da2 = (x - ax) * (x - ax) + (y - ay) * (y - ay), - db2 = (x - bx) * (x - bx) + (y - by) * (y - by), - dc2 = (x - cx) * (x - cx) + (y - cy) * (y - cy), - dd2 = (x - dx) * (x - dx) + (y - dy) * (y - dy); - - if (da2 <= r2 || db2 <= r2 || dc2 <= r2 || dd2 <= r2) { + x = fabs(x); + y = fabs(y); + double d2 = pow(x - 2, 2) + pow(y - 2, 2); + + if (d2 < r2) { printf("该点高度是10m\n"); } else { printf("该点高度是0m\n"); diff --git a/source/_posts/downloads.md b/source/_posts/downloads.md index 279d5ed..60f7e8f 100644 --- a/source/_posts/downloads.md +++ b/source/_posts/downloads.md @@ -44,4 +44,3 @@ tags: # 其它参考资料 [C语言程序设计习题选编.pdf](/~zhaozuohong/resources/C-experiments.ppt) - diff --git a/source/_posts/homework.md b/source/_posts/homework.md index 353e538..b050b65 100644 --- a/source/_posts/homework.md +++ b/source/_posts/homework.md @@ -19,5 +19,4 @@ tags: # 第三次作业 * [题目](/~zhaozuohong/homework3/) -* *答案暂未开放* - +* [答案](/~zhaozuohong/answer3)