没有合适的资源?快使用搜索试试~ 我知道了~
首页C Primer Plus 课后习题所有答案 完整版
资源详情
资源评论
资源推荐
C Primer Plus 课后练习答案(源码)
第一章 概览
略
第二章 C 语言概述
编程练习
1.编写一个程序,调用 printf()函数在一行上输出您的名和姓,再调用一次 printf()函数在
两个单独的行上输出您的名和姓,然后调用一对 printf()函数在一行上输出您的名和姓。输
出应如下所示(当然里面要换成您的姓名):
Anton Bruckner
Anton
Bruckner
Anton Bruckner
第一个输出语句
第二个输出语句
仍然是第二个输出语句
第三个和第四个输出语句
#include<stdio.h>
int main(void)
{
printf("He Jin");
printf("He");
printf("Jin");
printf("He Jin");
return(0);
}
2.编写一个程序输出您的姓名及地址。
#include<stdio.h>
int main(void)
{
printf("Name:He Jin");
printf("Address:CAUC");
return(0);
}
3.编写一个程序,把您的年龄转换成天数并显示二者的值。不用考虑平年( fractional year)
和闰年(leapyear)的问题。
#include<stdio.h>
int main(void)
{
int age=22;
printf("Age:%d\n",age);
printf("Day:%d\n",age*356);
return(0);
}
4.编写一个能够产生下面输出的程序:
For he's a jolly good fellow!
For he's a jolly good fellow!
For he's a jolly good fellow!
Which nobody can deny!
程序中除了 main()函数之外,要使用两个用户定义的函数:一个用于把上面的夸奖消息
输出一次:另一个用于把最后一行输出一次。
#include<stdio.h>
void printf1(void);
void printf2(void);
int main(void)
{
printf1();
printf1();
printf1();
printf2();
return(0);
}
void printf1(void)
{
printf("For he's a jolly good fellow!\n");
}
void printf2(void)
{
printf("Which nobody can deny!\n");
}
5.编写一个程序,创建一个名为 toes 的整数变量。让程序把 toes 设置为 10。再让程序计
算两个 toes 的和以及 toes 的平方。程序应该输出所有的 3 个值,并分别标识它们。
#include<stdio.h>
int main(void)
{
int toes=10;
int toes_add;
int toes_square;
toes_add=toes+toes;
toes_square=toes*toes;
printf("toes=%d\ntoes_add=%d\ntoes_square=%d\n",toes,toes_add,toes_square);
return(0);
}
6.编写一个能够产生下列输出的程序:
Smile ! Smile ! Smile
Smile ! Smile !
Smile !
在程序中定义一个能显示字符串 smile 卜一次的函数,并在需要时使用该函数。
#include<stdio.h>
void display(void);
int main(void)
{
display();
display();
display();
printf("\n");
display();
display();
printf("\n");
display();
printf("\n");
return(0);
}
void display(void)
{
printf("Smile!");
}
7.编写一个程序,程序中要调用名为 one_three()的函数。该函数要在一行中显示单词
"one",再调用 two()函数,然后再在另一行中显示单词"three"。函数 two()应该能在一行中显
示单词"two"。main()函数应该在调用 one_three()函数之前显示短语"starting now:",函数调
用之后要显示"done!"o 这样,最后的输出结果应如下所示:
starting now
one
two
three
done !
#include<stdio.h>
void one_three(void);
void two(void);
int main(void)
{
printf("starting now:\n");
one_three();
printf("done!\n");
return(0);
}
void one_three(void)
{
printf("One\n");
two();
printf("Three\n");
}
void two(void)
{
printf("Two\n");
}
第三章 数据和 C
编程练习
1.通过试验的方法(即编写带有此类问题的程序)观察系统如何处理整数上溢、浮点
数上溢和浮点数下溢的情况。
#include<stdio.h>
int main(void)
{
unsigned int a=4294967295;
float b=3.4E38;
float c=b*10;
float d=0.1234E-2;
printf("%u+1=%u\n",a,a+1);
printf("%e*10=%e\n",b,c);
printf("%f/10=%f\n",d,d/10);
return(0);
}
2.编写一个程序,要求输入一个 ASCII 码值(如 66),然后输出相应的字符。
#include<stdio.h>
int main(void)
{
char a;
scanf("%d",&a);
printf("%c\n",a);
return(0);
}
3.编写一个程序,发出警报声,并打印下列文字:
Startled by the sudden sound, Sally shouted, "By the Great Pumpkin, what was that!"
#include<stdio.h>
int main(void)
{
printf("\aStartled by the sudden sound,Sally shouted,\"By the Great pumpkin,what was
that!\"\n");
剩余188页未读,继续阅读
xzy521521
- 粉丝: 1
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
- SPC统计方法基础知识.pptx
- MW全能培训汽轮机调节保安系统PPT教学课件.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1