《C Primer Plus》(第6版)中文版 课后练习题 - Chapter 2
【先写几点总结】:
1.子函数有三点要注意:
a.子函数的函数原型要写在主函数之前
b.子函数的函数原型,要以分号结束
c.子函数的定义里,不能含有“retern 0”。
2.遇到需要换行的时候,可以直接使用:printf("\n")
practise 1
---------------
#include <stdio.h>
int main(void)
{
printf("Gustav Mahler\n"); //一开始我这里使用单引号一直报错,后来改成了双引号才成功
printf("Gstav\n");
printf("Mahler\n");
printf("Guster Mahler\n");
return 0;
}
practise 2
---------------
#include <stdio.h>
int main(void)
{
printf("我叫超\n");
printf("我来自美丽的连云港\n");
return 0;
}
practise 3
---------------
#include <stdio.h>
int main(void)
{
int a,b;
a = 27 ;
b = a * 365;
printf("我今年%d岁了,出生%d天了",a,b);
return 0;
}
practise 4
---------------
#include <stdio.h>
void jolly(void); //函数原型,最后别忘了加分号
void deny(void);
int main(void)
{
jolly();
jolly();
jolly();
deny();
return 0;
}
void jolly(void)//函数定义
{
printf("For he's a jolly good fellow!\n");//子函数里不能有 return 0字样
}
void deny(void)
{
printf("Which nobody can deny!\n");
}
practise 5
---------------
#include <stdio.h>
void br(void);
void ic(void);
int main(void)
{
br();
ic();
ic();
br();
return 0;
}
void br(void)
{
printf("Brazil,Russia,");
}
void ic()
{
printf("India,China\n");
}
practise 6
---------------
#include <stdio.h>
int main(void)
{
int toes,toes2,toes_2;
toes = 10;
toes2 = toes * 2;
toes_2= toes * toes;
printf("toes = %d ;\ntoes2 = %d;\ntoes_2 = %d.\n",toes,toes2,toes_2);
return 0;
}
practise 7
---------------
#include <stdio.h>
void wang(void);//函数原型
int main(void)
{
wang();wang();wang();printf("\n");//我真是太机智了
wang();wang();printf("\n");
wang();
return 0;
}
void wang(void)
{
printf("Smile!");
}
practise 8
---------------
#include <stdio.h>
void one_three(void);
void two(void);
int main (void)
{
printf("Starting now:\n");
one_three();
printf("two\n");
two();
printf("done!\n");
return 0;
}
void one_three(void)
{
printf("one\n");
}
void two(void)
{
printf("three\n");
}
我做了这么多,只是想给童年的自己做一个好榜样。

浙公网安备 33010602011771号