24_grade_C/笔记/第二课 作业解析.md
2025-02-28 21:48:28 +08:00

63 lines
1.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 作业
1. 输入一个数字x(可能包含小数),要求用户计算下列公式的值,并且输出。
((((3x + 2)x - 5)x - 1)x + 7)x - 6
```c
#include <stdio.h>
int main() {
double x;
double y;
printf("请输入x的值");
scanf("%lf", &x);
y = ((((3 * x + 2) * x - 5) * x - 1) * x + 7) * x - 6;
printf("计算出函数的值为:%lf", y);
return 0;
}
```
2. 输入一个数字r代表圆的半径计算圆的周长和面积
周长公式为 3.14 \* r \* 2
面积公式为 3.14 \* r \* r
```c
#include <stdio.h>
int main() {
int r;
double PI = 3.14;
double c, s;
printf("请输入圆的半径r");
scanf("%d", &r);
c = PI * 2 * r; // 计算圆周长
s = PI * r * r; // 计算圆面积
printf("圆的周长为:%lf, 圆的半径为:%lf", c, s);
return 0;
}
```
3. 输入九个数字,把他变成九宫格排列,输入的前三个数在第一行,中间三个数在第二行,后三个数在第三行,并且计算出每行每列的和,计算结果写在每一行每一列的最后一列,
```c
#include <stdio.h>
int main() {
int a1, a2, a3;
int a4, a5, a6;
int a7, a8, a9;
scanf("%d %d %d", &a1, &a2, &a3);
scanf("%d %d %d", &a4, &a5, &a6);
scanf("%d %d %d", &a7, &a8, &a9);
printf("%d %d %d | %d\n", a1, a2, a3, a1 + a2 + a3);
printf("%d %d %d | %d\n", a4, a5, a6, a4 + a5 + a6);
printf("%d %d %d | %d\n", a7, a8, a9, a7 + a8 + a9);
printf("——————\n");
printf("%d %d %d", a1 + a4 + a7, a2 + a5 + a8, a3 + a6 + a9);
return 0;
}
```