|
发表于 2019-1-20 22:59:01
|
显示全部楼层
0. 请问下边代码将打印多少个 'A'?
1. #include <stdio.h>
2.
3. int main()
4. {
5. int i, j;
6.
7. for (i = 0; i != 10, j != 10; i++)
8. {
9. for (j = 0; j < 10; j++)
10. {
11. putchar('A');
12. }
13. }
14.
15. putchar('\n');
16.
17. return 0;
18. }
10个
1. 请问下边代码会打印多少个 'B'?
1. #include <stdio.h>
2.
3. int main()
4. {
5. int i = 0;
6.
7. while (i++)
8. {
9. if (i > 10)
10. {
11. goto Label;
12. }
13. putchar('B');
14. }
15.
16. Label: putchar('\n');
17.
18. return 0;
19. }
0个
2. 请写出表达式 a = b = c = 5 中的"l-value"?(C 语言的术语 lvalue 指用于识别或定位一个存储位置的标识符。(注意:左值同时还必须是可改变的))
a b c都是l-value
3. 请问表达式 a = (b = 3, 4, c = b++ + 5, ++c + ++b); 执行后,整型变量 a、b、c 的值是?^
a=13 c=9 b=4
4. 请使用条件运算符求出变量 x 的绝对值,并存放到变量 z 中。
z = x > 0 ? x : -x;
5. C 语言其实在大部分情况下不使用 goto 语句也能做得很好,请尝试将下列代码段写成不带 goto 语句的版本。
A:
1. if (size > 12)
2. {
3. goto a;
4. }
5. goto b;
6. a: cost = cost * 1.05;
7. flag = 2;
8. b: bill = cost * flag;
if (size > 12)
{
cost = cost * 1.05;
flag = 2;
}
bill = cost * flag;
B:
1. if (ibex > 14)
2. {
3. goto a;
4. }
5. sheds = 2;
6. goto b;
7. a: sheds = 3;
8. b: help = 2 * sheds;
if (ibex > 14)
{
sheds = 3;
}
else sheds = 2;
help = 2 * sheds;
C:
1. readin: scanf("%d", &score);
2. if (score < 0)
3. {
4. goto stage2;
5. }
6. count++;
7. goto readin;
8. stage2: printf("count = %d\n", count);
while (1)
{
scanf (“%d”, &score0);
if (score < 0)
{
printf(“count = %d\n”, count);
break;
}
count++;
}
- /* 0 假设小甲鱼和黑夜手上均有 10000 元,小甲鱼以 10% 的单利息投资,
- 黑夜则以每年 5% 的复合利息投资。请编写一个程序,计算需要多少年黑夜手
- 头的 Money 才会超过小甲鱼? */
- # include <stdio.h>
- # include <math.h>
- int main()
- {
- float XIAOJIAYU, HEIYE;
- int year;
- year = 0;
- do
- {
- year++;
- XIAOJIAYU = 10000 * ( 1 + year * 0.1);
- HEIYE = 10000 * pow(1.05 , year);
- }
- while (XIAOJIAYU >= HEIYE);
- printf("%d年后,黑夜的投资额超过小甲鱼\n", year);
- printf("小甲鱼的投资额是:%.2f\n", XIAOJIAYU);
- printf("黑夜的投资额是:%.2f\n", HEIYE);
- return 0;
- }
- /* 1 小甲鱼中了双色球一等奖,扣除税收后还剩下 400 万人民币。假设小甲鱼把
- 这些钱做固定投资,每年可以获得 8% 的红利,但在每年的第一天,小甲鱼都会取出
- 50 万作为本年度的开销。
- 请编写一个程序,计算需要多久小甲鱼才会败光所有家产,再次回到一贫如洗?*/
- #include <stdio.h>
- int main()
- {
- signed float money = 4000000;
- int year = 0;
- do
- {
- year++;
- money = money - 500000;
- money = money * 1.08;
- }
- while (money >= 0);
- printf("%d年之后,小甲鱼败光了所有家产,一贫如洗。。\n", year);
- return 0;
- }
- /* 2 根据以下已知公式求 Pi 的近似值,要求正确计算出小数点后前 7 位(即3.1415926)*/
- #include <stdio.h>
- #include <math.h>
- int main()
- {
- int i = 1;
- double PI = 0;
- while (fabs( 1.0 / i ) > pow(10,-8))
- {
- PI = PI + (1.0 / i);
- i= (i > 0) ? i +2 : i - 2 ;
- i = -i;
- }
- PI = 4 * PI;
- printf("π=%.7f\n", PI);
- return 0;
- }
- /* 3 3. 这是一个有趣的古典数学问题:如果说兔子在出生两个月后,就有繁殖能力,
- 在拥有繁殖能力之后,这对兔子每个月能生出一对小兔子来。
- 假设所有兔子都不会死去,能够一直干下去,那么两年之后可以繁殖多少对兔子呢?*/
- //根据观察规律 第n个月的兔子是前两年兔子之和。
- #include<stdio.h>
- int main()
- {
- int i, rabbit, a, b;
- rabbit = 1;
- a = 0;
- b = 1;
- for ( i = 2 ; i <= 24 ; i++)
- {
- rabbit = a + b;
- a = b;
- b = rabbit;
- }
- printf("变成了%d对兔子\n", rabbit);
- return 0;
- }
复制代码 |
|