C_TA_Website/source/_posts/homework1.md
2020-10-30 13:59:49 +08:00

75 lines
1.9 KiB
Markdown

---
title: 第一次作业(题目)
date: 2020-10-30 09:47:21
tags:
---
# 第一题
写出下列程序运行的结果:
```C
#include <stdio.h>
int main()
{
int a, b;
char c1, c2;
float d, e;
double f, g;
long m, n;
unsigned int p, q;
a = 61; b = 62;
c1 = 'a'; c2 = 'b';
d = 3.56; e = -6.78;
f = 3157.890121; g = 0.123456789;
m = 50000; n = -60000;
p = 32768; q = 4000;
printf("sizeof: %d, a = %d, b = %d\n", sizeof(int), a, b);
printf("sizeof: %d, c1 = %c, c2 = %c\n", sizeof(char), c1, c2);
printf("sizeof: %d, d = %-6.2f, e = %-6.2f\n", sizeof(float), d, e);
printf("sizeof: %d, f = %-15.6f, g = %-15.12f\n", sizeof(double), f, g);
printf("sizeof: %d, m = %ld, n = %ld\n", sizeof(long), m, n);
printf("sizeof: %d, p = %u, q = %u\n", sizeof(unsigned), p, q);
return 0;
}
```
# 第二题
写出下列程序的运行结果:
```C
#include <stdio.h>
int main()
{
int i, j, m, n;
i = 8; j = 10;
m = ++i; n = j++;
printf("%d, %d, %d, %d\n", i, j, m, n);
return 0;
}
```
# 第三题
求下面算术表达式的值:
| # | 表达式 | 变量的值 |
| :---: | :------------------------------------- | :--------------------------------- |
| 1 | `3.5 + 1 / 2 + 56 % 10` | |
| 2 | `(a++ * 1 / 3)` | 设`a = 2` |
| 3 | `x + a % 3 * (int)(x + y) % 2 / 4` | 设`x = 2.5, a = 7, y = 4.7` |
| 4 | `(float)(a + b) / 2 + (int)x % (int)y` | 设a` = 2, b = 3, x = 3.5, y = 2.5` |
| 5 | `x = (x = ++y, x + 5, x / 5)` | 设`x = 3, y = 4` |
# 第五题
写出下面表达式运算后`a`的值,设原来`a = 12`。
1. `a += a`
2. `a *= 2 + 3`
3. `a /= a + a`
4. `a += a -= a *= a`