2.1
#include<stdio.h>
int main(void)
{
int q;
q = 1;
printf("%d is neat.\n",q);
return 0;
}
2.2
#include <stdio.h>
int main(void)
{
int four;
four = 4;
printf("%d\n",four);
return 0;
}
2.3
#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);
return 0;
}
2.4
// fathm_ft.c --把2英寻转换成英尺
#include<stdio.h>
int main(void)
{
int feet,fathoms;
fatnoms=2;
feet=6*fathoms;
printf("There are %d feet in %d fathoms!\n",feet, fathoms);
printf("Yes, I said %d feet!\n",9*fathoms);
return 0;
}
2.5
/* two_func.c --一个文件中包含两个函数 */
#include<stdio.h>
void butler(void);/* ANSI/ISO C函数原型*/
int main(void)
{
printf("I will summon the butler function.\n");
butler();
printf("Yes.Bring me some tea and writeable DVDs.\n");
return 0;
}
void butler(void)/*函数定义开始*/
{
printf("You rang ,sir?\n");
}
2.6
#include<stdio.h>
int main(void)
{
int n ,n2 ,n3;
n=5;
n2=n*n;
n3=n2*n2;
printf("n = %d,n squared = %d, n cubed = %d\n",n, n2, n3);
return 0;
}
代码需要多敲,注意规范,要避免很二的错误,比如:中文输入法下敲出括号。。。。