C primer plus (第六版) 第二章答案
采用vs编译器编译。
①
#include<stdio.h>
int main (void)
{
printf("Gustav Mahler\n");
printf("Gustav\n");
printf("Mathler\n");
printf("Gustav Mahler");
getchar();
return 0;
}
②
#include<stdio.h>
int main (void)
{
printf("My name is Gustav Mahler\n");
printf("Guangdong\n");
getchar();
return 0;
}
③
#include<stdio.h>
int main (void)
{
int years=22,days;
days=365*years;
printf("years=%d,days=%d\n",years,days);
getchar();
return 0;
}
④
#include<stdio.h>
void deny();
void jolly();
int main (void)
{
jolly();
jolly();
jolly();
deny();
getchar();
return 0;
}
void jolly()
{
printf("For he's a jolly good fellow!\n");
}
void deny()
{
printf("Which nobody can deny!\n");
}
⑤
#include<stdio.h>
void br();
void ic();
int main (void)
{
br();ic();printf("\n");
ic();printf("\n");
br();
getchar();
return 0;
}
void br()
{
printf("Brazil,Russia,");
}
void ic()
{
printf("India,China,");
}
⑥
#include<stdio.h>
int main ()
{
int toes;
toes=10;
printf("toes=%d,2toes=%d,toes2=%d\n",toes,2*toes,toes*toes);
getchar();
return 0;
}
⑦
#include<stdio.h>
void Smile(void);
int main (void)
{
Smile();Smile();Smile();printf("\n");
Smile();Smile();printf("\n");
Smile();
getchar();
return 0;
}
void Smile(void)
{
printf("Smile!");
}
⑧
#include<stdio.h>
void one_three(void);
void two(void);
int main (void)
{
printf("starting now\n");
one_three();
printf("done!");
getchar();
return 0;
}
void one_three(void)
{
printf("one\n");
two();
printf("three\n");
}
void two(void)
{
printf("two\n");
}