第一次C程序设计上机报告
姓名:张科星 学号:120705140 班级:12电信1班
任务1:创建一个基本程序。
实验内容:编写一个“显示华氏温度与摄氏温度的对照表”C程序
实验目的:掌握C语言开发环境,掌握简单C程序的编辑、编译。连接和运行的一般过程
#include<stdio.h>
int main()
{
int fahr,celsius;
int lower,upper,step;
lower=0;
upper=300;
step =20;
fahr =lower;
printf("张科星,120705140\n","");
while(fahr<=upper){
celsius=5*(fahr-32)/9;
printf("%d%d\n",fahr,celsius);
fahr=fahr+step;
}
return 0;
}
第一次运行程序效果截图 :
改代码,将prinf(“%d\t%d\n”,fahr,Celsius);改为prinf(“%d%d\n”,fahr,Celsius)
修改代码后运行效果截图:
#include<stdio.h>
int main()
{
int fahr,celsius;
int lower,upper,step;
lower=0;
upper=300;
step =20;
fahr =lower;
printf("张科星,120705140\n","");
while(fahr<=upper){
celsius=5*(fahr-32)/9;
printf("%d\t%d\n",fahr,celsius);
fahr=fahr+step;
}
return 0;
}
/*源程序: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);
}
程序运行效果截图
个人感想:第一次编程,用的是VS6版的,完全看不懂是什么意思,怎么来编写程序,在同学的帮助下,我才能勉勉强强编写下去。一个完整的程序至少包括头文件,主函数,函数体。在编写程序时我总结出来了程序不能缺少的步骤和项目:首先输入法应该为半角,其次是主函数void main,然后是以“{”开头,以“}”结尾,而在每一行末尾应加“;”,“{}”总是成对存在的。虽然第一次编写程序不是很顺利,但我会慢慢学习它,直到熟练为止。