C语言概述
2.1
/first.c
#include <stdio.h>
int main(void)
{
int num;
num = 1;
printf("I am a simple");
printf("computer.\n");
printf("My favorite number is %d because it is first.\n", num);
getchar();
return 0;
}
2.2
//fathm_ft.c--把2英寻转化为英尺
#include <stdio.h>
int main(void)
{
int feet, fathoms;
fathoms = 2;
feet = 6 * fathoms;
printf("There are %d feet in %d fathoms!\n", feet, fathoms);
printf("Yes, I said %d feet!\n", 6 * fathoms);
getchar();
return 0;
}
2.3
/* two_func.c--一个文件中包含两个函数*/
#include <stdio.h>
void butler(void);
int main(void)
{
printf("I will summon the butler function.\n");
butler();
printf("Yes. Bring me some tea and writeable DVDs.\n");
getchar();
return 0;
}
void butler(void)
{
printf("You rang, sir?.\n");
}
2.4
/*nogood.c--有错误的程序*/
#include <stdio.h>
int main(void)
{
int n; int n2; int n3;
/*该程序有多处错误*/
n = 3;
n2 = n*n;
n3 = n2*n;
printf("n = %d, n squared = %d, n cubed = %d\n", n, n2, n3);
getchar();
return 0;
}
2.5略