ex2.1
// ex_2.1
#include <stdio.h>
int main(void)
{
printf("Tim Wu\n");
printf("Tim\nWu\n");
printf("Tim ");
printf("Wu\n");
return 0;
}
ex2..2
// ex_2.2
#include <stdio.h>
int main(void)
{
printf("NAME: Tim Wu\n");
printf("ADDRESS: Jing An District Shanghai China\n");
return 0;
}
ex2.3
// ex_2.3
#include <stdio.h>
int main(void)
{
int age = 0;
int days = 0;
printf("How old are you?\n");
scanf("%d", &age);
days = age * 365;
printf("You've been lived for %d days.", days);
return 0;
}
ex2.4
// ex_2.4
#include <stdio.h>
void jolly(void)
{
printf("For he's a jolly good fellow!\n");
}
void deny(void)
{
printf("Which nobody can deny!\n");
}
int main(void)
{
jolly();
jolly();
jolly();
deny();
return 0;
}
ex2.5
// ex_2.5
#include <stdio.h>
void br(void)
{
printf("Brazil, Russia");
}
void ic(void)
{
printf("India, China");
}
int main(void)
{
br();
printf(", ");
ic();
printf("\n");
ic();
printf(",\n");
br();
return 0;
}
ex2.6
// ex_2.6
#include <stdio.h>
int main(void)
{
int toes = 10;
int toes_twice = toes * 2;
int toes_squared = toes * toes;
printf("The value of toes is %d.\n", toes);
printf("The value of twice toes is %d.\n", toes_twice);
printf("The value of squared toes is %d.\n", toes_squared);
return 0;
}
ex2.7
// ex_2.7
#include <stdio.h>
void printSmile(int n)
{
int i;
for (i = 0; i < n; i++)
printf("Smile!");
printf("\n");
}
int main(void)
{
printSmile(3);
printSmile(2);
printSmile(1);
return 0;
}
ex2.8
// ex_2.8
#include <stdio.h>
void two(void);
void one_three(void);
int main(void)
{
printf("starting now:\n");
one_three();
printf("done.\n");
return 0;
}
void two(void)
{
printf("two\n");
}
void one_three(void)
{
printf("one\n");
two();
printf("three\n");
}