发布第三次答案

This commit is contained in:
Zhao Zuohong 2020-10-30 15:57:44 +08:00
parent b01ba87404
commit 10658b7245
3 changed files with 9 additions and 13 deletions

View file

@ -1,8 +1,10 @@
--- ---
title: 第三次作业(答案) title: 第三次作业(答案)
date: 2020-10-30 15:53:35
tags: tags:
--- ---
# P108-3 # P108-3
写出下面各逻辑表达式的值。设`a = 3`,`b = 4`,`c = 5`。 写出下面各逻辑表达式的值。设`a = 3`,`b = 4`,`c = 5`。
@ -133,14 +135,11 @@ int main()
```C ```C
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h>
int main() int main()
{ {
double r2 = 1; double r2 = 1;
double ax = 2, ay = 2,
bx = -2, by = 2,
cx = -2, cy = -2,
dx = 2, dy = -2;
double x, y; double x, y;
printf("请分别输入所在位置的的x、y坐标:\nx = "); printf("请分别输入所在位置的的x、y坐标:\nx = ");
if (scanf("%lf", &x) != 1) { if (scanf("%lf", &x) != 1) {
@ -152,12 +151,11 @@ int main()
fprintf(stderr, "非法输入!\n"); fprintf(stderr, "非法输入!\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
double da2 = (x - ax) * (x - ax) + (y - ay) * (y - ay), x = fabs(x);
db2 = (x - bx) * (x - bx) + (y - by) * (y - by), y = fabs(y);
dc2 = (x - cx) * (x - cx) + (y - cy) * (y - cy), double d2 = pow(x - 2, 2) + pow(y - 2, 2);
dd2 = (x - dx) * (x - dx) + (y - dy) * (y - dy);
if (da2 <= r2 || db2 <= r2 || dc2 <= r2 || dd2 <= r2) { if (d2 < r2) {
printf("该点高度是10m\n"); printf("该点高度是10m\n");
} else { } else {
printf("该点高度是0m\n"); printf("该点高度是0m\n");

View file

@ -44,4 +44,3 @@ tags:
# 其它参考资料 # 其它参考资料
[C语言程序设计习题选编.pdf](/~zhaozuohong/resources/C-experiments.ppt) [C语言程序设计习题选编.pdf](/~zhaozuohong/resources/C-experiments.ppt)

View file

@ -19,5 +19,4 @@ tags:
# 第三次作业 # 第三次作业
* [题目](/~zhaozuohong/homework3/) * [题目](/~zhaozuohong/homework3/)
* *答案暂未开放* * [答案](/~zhaozuohong/answer3)
<!-- * [答案](/~zhaozuohong/answer3) -->