//Listing 2-1 print_name
#include <stdio.h>
int main(void)
{
printf("Gustav Mahler\n");
printf("Gustav\n");
printf("Mahler\n");
printf("Gustav");
printf(" Mahler\n");
return 0;
}
//Listing 2-2 print_name_address
#include <stdio.h>
int main(void)
{
printf("my name is:\"Sherlock·Holmes \"\n");
printf("you can find me at: No.211b Baker Street\n");
return 0;
}
/*Listing 2-3 age_day*/
#define AGE 18
#include <stdio.h>
int main(void)
{
printf("my age is:%d\n", AGE);
printf("convert to day is:%d\n", 18*365);
return 0;
}
//Listing 2-4 easy_function
#include <stdio.h>
int main(void)
{
jolly();
jolly();
jolly();
deny();
return 0;
}
void jolly(void)
{
printf("For he's jolly good fellow!\n");
}
void deny(void)
{
printf("Which nobody can deny!");
}
//Listing 2-5 easy_function2
#include <stdio.h>
int main(void)
{
br();
printf(" ,");
ic();
printf("\n");
ic();
printf(",\n");
br();
return 0;
}
void br()
{
printf("Brazil, Russia");
}
void ic()
{
printf("India, China");
}
//Listing 2-6 toes
#include <stdio.h>
int main(void)
{
int toes = 10;
printf("Original \t Square \t cube\n");
printf("%d \t %d \t %d \t", toes, toes*toes, toes*toes*toes);
return 0;
}
//Listing 2-7 smile
#include <stdio.h>
int main(void)
{
for(int i = 0;i < 3;i++)
{
for(int j = 3-i;j > 0;j--)
{
smile();
}
printf("\n");
}
return 0;
}
void smile()
{
printf("Smile!");
}
//Listing 2-8 one_two_three
#include <stdio.h>
void one_three();
void two();
int main(void)
{
printf("starting now:\n");
one_three();
printf("down!\n");
return 0;
}
void one_three()
{
printf("one\n");
two();
printf("three\n");
}
void two()
{
printf("two\n");
}