#第二章习题
#include <stdio.h>
int main() {
//1.编写一个程序,调用一次 printf()函数,把你的姓名打印在一行。
//再调用一次 printf()函数,把你的姓名分别打印在两行。
//然后,再调用两次printf()函数,把你的姓名打印在一行。
//输出应如下所示(当然要把示例的内容换成你的姓名):
printf("HelloWorld!\n");
printf("hello\nWorld!\n");
printf("hello");
printf("world!\n");
//return 0;程序结束的标志,写出这个程序将不会继续向下进行
//3.编写一个程序把你的年龄转换成天数,并显示这两个值。这里不用考虑闰年的问题。
printf("This year,you are %d years old\nand you spend %d "
"days in this life\n",20,20*365);
//6.编写一个程序,创建一个整型变量toes,并将toes设置为10。
//程序中还要计算toes的两倍和toes的平方。该程序应打印3个值,并分别描述以示区分
int toes=10;
int sum;
sum=2*toes+toes*toes;
printf("sum is %d\n",sum);
//8.在C语言中,函数可以调用另一个函数。
// 编写一个程序,调用一个名为one_three()的函数。
// 该函数在一行打印单词“one”,再调用第2个函数two(),
// 然后在另一行打印单词“three”。two()函数在一行显示单词“two”。
// main()函数在调用 one_three()函数前要打印短语“starting now:”,
// 并在调用完毕后显示短语“done!”。因此,该程序的输出应如下所示:
printf("starting now\n");
one_three();
printf("done!\n");
}
void two(){
printf("two\n");
}
void one_three(){
printf("one\n");
two();
printf("three\n");
《 C Prime Plus》前两章讲的东西都很基础,对应的编程训练题目比较容易,所以只挑选出了几个稍微有点复杂的题目给出的答案,希望能给像我这样编程不入门的小白一点借鉴