第1章:课后习题答案


一、单项选择题

1—5 CAADC
6—10 BCACC
11—15 DBCBC

二、填空题

  1. .c
  2. 编辑、编译、连接、执行
  3. 二进制目标、可执行
  4. 函数
  5. 分号
  6. 增强程序的可读性,不会影响程序的功能和正确性
  7. 库函数
  8. 字母、数字、下划线,字母、下划线
  9. 机器语言、汇编语言、高级语言
  10. 方法和步骤
  11. //单行注释、/* */多行注释

三、编程题

1.从键盘输入两个整数,调用函数库,计算这两个数的差值

#include<stdio.h>
#include<math.h>
int main()
{
    
    
	int a,b;
	printf("输入两个整数");
	scanf("%d%d",&a,&b);
	printf("%d\n",abs(a-b));
	return 0;
} 

2.略

3.从键盘输入整数到变量a和b中,然后交换a和b的值并输出

#include<stdio.h>
int main()
{
    
    
	int a,b,t=0;
	printf("输入两个整数");
	scanf("%d%d",&a,&b);
	t=b;
	b=a;
	a=t;
	printf("a=%d,b=%d\n",a,b);
	return 0;
} 

4.从键盘输入直角三角形的两条直角边的长度,求斜边的长度和三角形的面积,计算结果保留两位小数

#include<stdio.h>
#include<math.h>
int main()
{
    
    
	float a,b;
	printf("输入直角三角形两条直角边的长度");
	scanf("%f%f",&a,&b);
	printf("斜边的长度=%3.2f,三角形的面积=%3.2f",sqrt(a*a+b*b),(a*b)/2);
	return 0;
} 

5.从键盘输入两个实数x和y,求x的y方+|y|

#include<stdio.h>
#include<math.h>
int main()
{
    
    
	double x,y;
	printf("输入两个实数");
	scanf("%lf%lf",&x,&y);
	printf("%lf",pow(x,y)+abs(y));
	return 0;
} 

6.从键盘输入圆柱体的半径和高,求圆柱体的表面积和体积

#include<stdio.h>
#include<math.h> 
int main(){
    
    
	double r,h;
	printf("输入圆柱体的半径和高");
	scanf("%lf%lf",&r,&h);
	printf("圆柱体的表面积=%lf,圆柱体的体积=%lf",2*3.14*r*(r+h),3.14*r*r*h);
	return 0;
} 


如果有问题,可以在评论区留言

猜你喜欢

转载自blog.csdn.net/buxiangquaa/article/details/114534713