第一次C程序设计上机报告
姓名:曹秀佳 学号:120705144 班级:12电信1班
任务1:创建一个基本程序
实验内容:编写一个“显示华氏温度与摄氏温度对照表”C程序
实验目的:掌握C语言开发工具,简单掌握C程序的编辑、编译、连接和运行的一般过程
我的程序:
//******************************
//对fahr=0,20,…,300
//打印华氏温度与摄氏温度对照表
//Code by 曹秀佳 44 2013/3/8
//******************************
#include<stdio.h>
int main()
{
int fahr,celsius;
int lower,upper,step;
lower=0; /* 温度表的下限 */
upper=300; /* 温度表的上限 */
step=20; /* 步长 */
fahr=lower;
printf("曹秀佳,44\n", "");
while(fahr<=upper){
celsius=5 * (fahr-32)/9;
printf("%d %d\n", fahr,celsius);
fahr=fahr+step;
}
return 0;
}
第一次运行程序"错误列表"
错误 1. errorC2146:语法错误:缺少“:”(在标识符“upper”的前面)
错误原因及其解决方法:忘记录入行代码的结尾的“;”号,录入后问题解决
程序运行效果截图:
![](https://img-my.csdn.net/uploads/201303/12/1363055206_4729.jpg)
修改代码,将printf("%d %d\n", fahr,celsius);改为printf("%d\t %d\n", fahr,celsius);
修改代码后,程序运行效果截图:
![](https://img-my.csdn.net/uploads/201303/12/1363055381_2282.jpg)
任务2:进一步熟悉C语言编写的一般程序
实验内容:运行作业“例6-3”程序
实验目的:加深理解C程序的编辑、编译、连接和运行的一般过程
我的程序:
//******************************
//函数间的参数值单向传递方式
//Code by 曹秀佳 44 2013/3/10
//******************************
/*源程序: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);
}
第一次运行程序"错误列表"
无
程序运行效果截图:
![](https://img-my.csdn.net/uploads/201303/12/1363055462_1271.jpg)
第一次C程序设计上机心得体会:
第一个C程序做的过程中感觉比较纠结,经常忘记在每段末加分号,错误也比较多。
知识点总结:
1.一个程序至少要有一个函数,main 函数常称为主函数。
2.函数中所有语句都包括在一对花括号中。
3.一般每段末都要加上分号。