C Primer Plus_第二章_C语言概述_复习题与编程练习

REVIEW

1.如何称呼C程序的基本模块?
ans
它们被称为函数

2.什么是语法错误?给出一个英语例子和一个C语言例子
me
C的语法错误是指把正确的C符号放在了错误的位置
likes coding He. 
int main(void)
()
ans
语法错误就是指违背了如何把语句或程序放置在一起的规则。
Me speaks English good.
printf "where are the parentheses?";

3.什么是语义错误?给出一个英语例子和一个C语言例子
ans
语义错误就是指含义上的错误(编译不出语法错误)。
My favorite singer is GuoDegang.
thrice_n = 3 + n;

4.评定下面的程序
#include <</font>studio.h>
int main(void)  
({
int s;

s: = 56;s= 56;
printf ("There are s%d weeks in a year.",s);
return 0;
)}



PRACTICE
1.利用printf函数输出姓名
#include
int main(void)
{
printf("Tom Smith\n");
printf("Tom\nSmith\n");
printf("Tom ");
printf("Smith\n");
 
return 0;
}
 
2.输出您的姓名和地址

#include
int main(void)
{
 printf("Name: Tom Smith\n");
 printf("Add: China AnHui MaAnShan\n");
 return 0;
}
 
3.把年龄转换成天数并显示二者的值

#include
int main(void)
{
 int age;
 int day;
 age = 24;
 printf("tom is %d years old\n",age);
 printf("tom has been on earth for %d days\n",age*365);
 return 0;
}
 
4.

#include
void prnt1(void);
void prnt2(void);
int main(void)   //主函数定义用 int main(void)
{
 prnt1();
 prnt1();
 prnt1();
 prnt2();
 return 0;
}
void prnt1(void)  //子函数定义用 void func(void)
{
 printf("For Tom is a jolly good fellow!\n");
}
void prnt2(void)
{
 printf("Which nobody can deny!!!\n");
}
 
5.

#include
int main(void)
{
 int toes,t_sqr,t_sum;
 toes = 10;
 t_sqr = toes * toes;
 t_sum = toes + toes;
 printf("toes = %d\ntoes and = %d\ntoes square = %d\n",toes,t_sum,t_sqr);
 
 return 0;
}
 
6.

#include
void prt_s(void);
void prt_n(void);
int main(void)
{
 prt_s();
 prt_s();
 prt_s();
 prt_n();
 prt_s();
 prt_s();
 prt_n();
 prt_s();
 prt_n();
 return 0;
}
void prt_s(void)
{
 printf("Smile!");
}
void prt_n(void)
{
 printf("\n");
}
 
7.

#include
void one_three(void);
void two(void);
int main(void)
{
 printf("starting now:\n");
 one_three();
 printf("done!\n");
 return 0;
}
void one_three()
{
 printf("one\n");
 two();
 printf("three\n");
}
void two()
{
 printf("two\n");
}
posted @ 2016-08-05 08:02  行动救赎  阅读(371)  评论(0编辑  收藏  举报