2020-12-31

C Primer Plus 第六版(中文版)第六章编程练习答案第二章

转眼都大三了,感觉自己什么都没学到。以前总是眼高手低,简单的不想看,难的又不会,现在从最基础的看起。
2-1

#include 
int main(void)
{
     
	printf("AN nian\n");
	printf("An\nnian\n");
	printf("AN ");
	printf("nian");
	return 0;
}

2-3

//年龄转化为天数
#include 
int main(void)
{
     
	int age,days;
	age = 20;
	days = age*365;
	printf("我今年%d岁,我已经出生了%d天",age,days);
	return 0;
 } 

2-4

//调用两个自定义函数 
#include 
void jolly(void);
void deny(void);
int main(void)
{
     
	jolly();
	jolly();
	jolly();
	deny();
}
void jolly(void){
     
	printf("for he's a jolly good fellow!\n");
}
void deny(void){
     
	printf("which nobody can deny");
}

2-5

#include 
void br(void);
void ic(void);
int main()
{
     
	br();
	printf(",");
	ic();
	printf("\n");
	ic();
	printf(",\n");
	br();
}
void br(void){
     
	printf("Brazil,Russia");
}
void ic(void){
     
	printf("India,China");
}

2-6

#include 
int main(){
     
	int toes,toeses,toesfang;
	toes = 10;
	toeses = 2*toes;
	toesfang = toes*toes;
	printf("toes=%d,toes的两倍%d,toes的平方%d",toes,toeses,toesfang); 
	return 0;
}

2-7

#include 
void smile(void);
int main(){
     
	smile();smile();smile();
	printf("\n");
	smile();smile();
	printf("\n");
	smile();
}
void smile(void){
     
	printf("smile!");
}

2-8

#include 
void one_three();
void two();
int main()
{
     
	printf("string now:\n,./lkm");
	one_three();
	
	printf("done!");
}
void one_three(){
     
	printf("one\n");
	two();
	printf("three\n");
}
void two(){
     
	printf("two\n");
}

在函数定义中,void含义为无类型,可以省略

你可能感兴趣的:(c语言,c语言)