现附上我对第二章习题的解答,仅供参考,欢迎交流
//2.12.1
//2.12.1打印特定内容
# include <stdio.h>//引用printf
int main(void)
{
printf("Gustav Mahler\n");
printf("Gustav\nMahler\n");
printf("Gustav Mahler");
return 0;
}
//2.12.3
//2.12.3将你的年龄转换成天数
# include <stdio.h>
int main()
{
int age;//定义整型变量
printf("Please enter your age\n");
scanf("%d", &age);
printf("The %d year(s) convert to %d days", age, age * 365);
return 0;
}
//2.12.4
//2.12.4打印特定内容
# include <stdio.h>
void jolly(void);//ANSI/ISO函数原型
void deny(void);
int main(void)
{
jolly();
jolly();
jolly();
deny();
return 0;
}
void jolly(void)
{
printf("For he is a jolly good fellow!\n");
}
void deny(void)
{
printf("Which nobody can deny!\n");
}
//2.12.5
//2.12.5打印特定内容
# include <stdio.h>
void br(void);
void ic(void);
int main(void)
{
br();
printf(",");ic();
printf("\n");ic();
printf("\n");br();
return 0;
}
void br(void)
{
printf("Brazil,Russia");
}
void ic(void)
{
printf("India,China");
}
//2.12.6
//2.12.6整型toes的计算
# include <stdio.h>
int main(void)
{
int toes = 10;
printf("toes=%d\n 2*toes=%d\n toes^2=%d\n", toes, toes * 2, toes * toes);
return 0;
}
//2.12.7
//2.12.7打印特定内容
# include <stdio.h>
void br(void);
int main(void)
{
br();br();br();
printf("\n");
br();br();
printf("\n");
br();
return 0;
}
void br(void)
{
printf("Smile!");
}
//2.12.8
//2.12.8打印特定内容
# include <stdio.h>
void one_three(void);
void two(void);
int main(void)
{
printf("starting now\n");
one_three();
printf("\n");
two();
printf("\n");
printf("three\ndone!");
return 0;
}
void one_three(void)
{
printf("one");
}
void two(void)
{
printf("two");
}
如有不足,欢迎指正