姓名:尉桢 学号:120705142 班级:电子信息1班
第一次上机课
//******************************
//对fahr=0,20,…,300
//打印华氏温度与摄氏温度对照表
//Code by 尉桢 42 2013/3/8
//******************************
#include<stdio.h>
int main()
{
int fahr,celsius;
int lower,upper,step;
lower=0; /* 温度表的下限 */
upper=300; /* 温度表的上限 */
step=20; /* 步长 */
fahr=lower;
printf("尉桢,42\n", "");
while(fahr<=upper){
celsius=5 * (fahr-32)/9;
printf("%d %d\n", fahr,celsius);
fahr=fahr+step;
}
return 0;
}
修改
例题6-3
/*源程序:exp6_3.cpp*/
#include<stdio.h>
void main()
{
void swap(int x,int y);
int a,b;
a=2,b=6;
printf("调用前:a=%d,b=%d\n",a,b);
swap(a,b);
printf("调用后:a=%d,b=%d\n",a,b);
}
void swap(int x,int y)
{
int temp;
printf("交换前:x=%d,y=%d\n",x,y);
temp=x;
x=y;
y=temp;
printf("交换后;x=%d,y=%d\n",x,y);
}
体会:
第一次接触感觉很烦,因为要注意很多,比如全角半角,还要注意不要漏写最后的符号。
总结
1、每个C程序都需要头文件
2、每个程序必须有主函数
3、程序注释:解释程序是做什么的
4、代码注释:介绍行代码的含义