一、知识点复习
1.C语言的基本模块——函数。
2.语法错误:违反了组成语句或程序的规则。
3.语义错误:含义错误。
4.标识符(变量名)的命名:可以用小写字母、大写字母、数字和下划线来命名,且名称的第一个字符必须是字符或下划线,不能是数字。
5.实参&形参:实参——传递给函数的特定值;
形参——储存值的变量。
6.转义序列:用于代表难以表示或无法输入的字符。例如\t——Tab键;
\b——退格键;
\n——换行符。
7.有返回值的C函数要有return语句。
8.无论main()处于什么位置,程序执行都是从它开始。
9.C标准建议,为程序中所有用到的函数提供函数原型。(先声明再定义)
二、编程练习
1.
#include<stdio.h>
int main(void)
{
printf("first_name last_name\n");//将名和姓打印在一行
printf("first_name\nlast_name\n");//将名和姓分别打印在两行
printf("first_name ");//打印名,不换行
printf("last_name\n");//打印姓,结果将与名显示在一行
return 0;
}
2.
/*date:2018-2-1
author:Alice_12
function:print name and address
*/
#include<stdio.h>
int main(void)
{
printf("name:Alice_12\n");
printf("address:Mars\n");
return 0;
}
/*date:2018-2-1
author:Alice_12
function:convert old into days and display both numbers(regardless of leap year)
*/
#include<stdio.h>
int main(void)
{
int old;//声明年龄
int days;//声明天数
old = 18;//定义年龄
days = old * 365;//根据年龄计算天数
printf("old:%d\n", old);//%提醒程序要在此处打印一个变量,d表明把变量作为十进制整数打印
printf("convert %d years into days:%d\n", old, days);
return 0;
}
4.
#include<stdio.h>
void jolly(void);//声明函数jolly()
void deny(void);
int main(void)
{
jolly();//调用函数jolly()
jolly();
jolly();
deny();
return 0;
}
void jolly(void)//定义函数jolly()
{
printf("For he's a jolly good follow!\n");
}
void deny(void)
{
printf("Which nobody can deny!\n");
}
5.
6.
/*date:2018-2-1
author:Alice_12
function:display-Brazil,Russia,India,China
India,China
Brazil,Russia
*/
#include<stdio.h>
void br(void);
void ic(void);
int main(void)
{
printf("Brazil,Russia,India,China\n");
ic();
br();
return 0;
}
void br(void)
{
printf("Brazil,Russia\n");
}
void ic(void)
{
printf("India,China\n");
}
6.
/*date:2018-2-1
author:Alice_12
function:create toes into 10 and display toes、double toes、toes*toes
*/
#include<stdio.h>
int main(void)
{
int toes;
int double_toes;
int two_toes;
toes = 10;
double_toes = toes + toes;
two_toes = toes * toes;
printf("toes=%d\n", toes);
printf("double_toes=%d\n", double_toes);
printf("two_toes=%d\n", two_toes);
return 0;
}
7.
8.
/*date:2018-2-1
author:Alice_12
function:display-smile!smile!smile!
smile!smile!
smile!
*/
#include<stdio.h>
void s(void);
int main(void)
{
printf("smile!smile!");
s();
printf("smile!");
s();
s();
return 0;
}
void s(void)
{
printf("smile!\n");
}
8.
/*date:2018-2-1
author:Alice_12
function:display-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");
}
三、总结
1.stdio.h含义为标准输入\输出头文件,其中包含了供编译器使用的输入和输出函数,如printf()。2.打印换行使用\n。3.博客编辑有点难用,逼死强迫症。