C Primer Plus(第五版)中文版课后编程题全解
C Primer Plus(第五版)中文版[PDF+源代码]下载 http://www.linuxidc.com/Linux/2012-05/60075.htm
第二章 C语言概述 编程练习
1.编写一个程序,调用printf()函数在一行上输出您的名和姓,再调用一次printf()函数在两个单独的行上输出您的名和姓,然后调用一对printf()函数在一行上输出您的名和姓。输出应如下所示(当然里面要换成您的姓名):
Anton Bruckner
Anton
Bruckner
Anton Bruckner
第一个输出语句
第二个输出语句
仍然是第二个输出语句
第三个和第四个输出语句
#include<stdio.h>
int main(void)
{
printf("He Jin\n");
printf("He\n");
printf("Jin\n");
printf("He Jin\n");
return(0);
}
2.编写一个程序输出您的姓名及地址。
#include<stdio.h>
int main(void)
{
printf("Name:He Jin\n");
printf("Address:CAUC\n");
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!");
}
C Primer Plus(第五版)中文版课后编程题全解doc文档可以到Linux公社资源站下载:
------------------------------------------分割线------------------------------------------
免费下载地址在 http://linux.linuxidc.com/
用户名与密码都是www.linuxidc.com
具体下载目录在 /2017年资料/1月/31日/C Primer Plus(第五版)中文版课后编程题全解doc/
下载方法见 http://www.linuxidc.com/Linux/2013-07/87684.htm
------------------------------------------分割线------------------------------------------
本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-01/140082.htm