没有合适的资源?快使用搜索试试~ 我知道了~
C语言程序设计-张磊-课后习题答案.pdf
5星 · 超过95%的资源 4 下载量 83 浏览量
2022-11-03
14:31:24
上传
评论
收藏 403KB PDF 举报
温馨提示
试读
28页
C语言程序设计_张磊_课后习题答案
资源推荐
资源详情
资源评论
第三章
二.
1.
#include<stdio.h>
void main()
{
flo
at weigh
t=0
;
float pay=0;
printf("请输入邮件重量(单位:g):");
scanf("
%f
",&weigh
t)
;
if(weight>100)
{
pay=100*0.05+(weight-100)*0.02;
}
else
{
pay=weight*0.05;
}
p
ri
n
t
f
("
\
n
需
要支
付
:
%
f 元
"
,
p
ay
)
;
}
2
.
#include<stdio.h>
void main()
{
float x=0;
float y=0;
printf("请输入 x 的值:");
scanf("%f",&x);
if(x<=0)
{
y
=
x
;
}
else if(x>0 && x<1)
{
y=2*x;
}
else
{
公众号【电气工程狗】免费分享更多资源
1/28
y=3*x*x-6*x+7;
}
printf("\n
y 的值为:%f"
,y);
}
3.
#include<stdio.h>
void main()
{
int a
=0,b=0
,c=0
;
int temp=0;
printf("请以空格隔开输入 3 个整数\n");
scanf("
%d
%d %d",&a
,&
b,&c);
temp=a;
if(temp<b)
{
a=b;
b=temp;
temp=a;
}
if(temp<c)
{
a=c;
c=temp;
temp=a;
}
if(b<c)
{
temp=b;
b=c;
c=temp;
}
printf("\n%d>%d>%d",a,b,c);
}
4.
v
o
id
m
a
i
n(
)
{
int a=0;
printf("请输入一个整数:");
scanf("%d",&a);
if(a%3==0&&a%5==0)
{
printf("%d 该数既能被 3 整除又能被 5 整除",a);
公众号【电气工程狗】免费分享更多资源
2/28
}
else
{
printf("%d 该数不能被 3 整除同时又能被 5 整除",a);
}
}
5.
void main()
{
int i=0;
printf("请输入一个整数:");
sc
an
f("%d",&
i)
;
switch(i)
{
case 1:printf("星期一");break;
case 2:printf("星期二");break;
case 3:printf("星期三");break;
case 4:printf("星期四");break;
case 5:printf("星期五");break;
case 6:printf("星期六");break;
c
as
e
7
:
pr
i
n
t
f(
"
星
期
天"
)
;
b
re
a
k
;
d
ef
a
u
l
t:
p
r
i
nt
f
(
"
输入
数
据
不
合法
\
n
"
);
}
}
6.
#include<math.h>
void main()
{
float a=0,b=0,c=0;
float dt=0;
printf("请以空格隔开输入 a b c 的值:");
scanf("%f %f %f",&a,&b,&c);
dt=b*b-4*a*c;
if(dt<0)
{
printf("\n 无解");
}
else if(dt==0)
{
printf("\n 有唯一解为:%f\n",-b/2*a);
}
e
l
s
e
公众号【电气工程狗】免费分享更多资源
3/28
{
printf("x1 为:%f x2 为:%f\n",(sqrt(dt))/2.0*a-b,(-(b+sqrt(dt))/2.0*a));
}
}
7.
void main()
{
char ch;
scan
f("%c"
,&ch
);
if(ch>='a'&&ch<='z'||ch>='A'&&ch<='Z')
{
printf("这是字母:%c",ch);
}
else if(ch>='0'&&ch<='9')
{
printf("这是数字:%c",ch);
}
else
{
pr
i
n
t
f(
"
这
是
空白
"
)
;
}
}
8
.
void main()
{
int n=0,i=1;
printf("输入 n:");
scanf("%d",&n);
int sum=1;
loop:sum=sum*i;
if(i<n)
{
i++;
go
t
o
l
oo
p
;
}
printf("\n%d!=%d\n",n,sum);
}
9.
void main()
{
i
n
t
n
um
=
0
,
te
m
p
=
0,
a
=
1
;
公众号【电气工程狗】免费分享更多资源
4/28
int i = 0;
//位数
printf("输入一个整数:");
sc
anf("%d",
&num);
temp=num;
printf
("\n 逆序输出为:");
do
{
i++;
a=a*10;
prin
tf("%d
",nu
m%10);
num = num /10;
}while(num > 0);
printf("\n 位数:%d\n",i);
printf("%d",a);
printf("分别打印每一位数:");
while(i>0)
{
a=a/10;
printf("%d\t",temp/a);
temp=temp-temp/a*a;
i--;
}
}
第四
章
一.
选择题
1~8:
C C C A A C
C A
二.程序分析题
1. n
%4!=
0 2. 1
00 3.
1 4. 1
三.
1.
void
main
()
{
in
t m
=0,
n=
0,s
um
=1;
公众号【电气工程狗】免费分享更多资源
5/28
剩余27页未读,继续阅读
小鸭文库
- 粉丝: 141
- 资源: 5901
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页