您的位置:首页 > 其它

第一次C程序设计上机报告

2013-03-11 22:21 197 查看
我的第一次程序

*********************************************

显示华氏温度与摄氏温度对照表

我的程序:

//*******************************
//对fahr=0,20,...,300
//打印华氏温度与摄氏温度对照表
//code by 潘卉文 45 12-3-8
//*******************************

#include<stdio.h>
int main()
{
int fahr,celsius;
int lower,upper,step;

lower=0;
upper=300;
step=20;
fahr=lower;

printf("潘卉文,120705245\n","");
while(fahr<=upper)
{
celsius=5*(fahr-32)/9;
printf("%d%d\n",fahr,celsius);
fahr=fahr+step;
}
return 0;
}

 

运行结果:


 

 

修改代码将ptinft("%d%d\n",fahr,celsius)改成prinft("%d\t%d\n",fahr,celsius)

 

//*******************************
//对fahr=0,20,...,300
//打印华氏温度与摄氏温度对照表
//code by 潘卉文 45 12-3-8
//*******************************

#include<stdio.h>
int main()
{
int fahr,celsius;
int lower,upper,step;

lower=0;
upper=300;
step=20;
fahr=lower;

printf("潘卉文,120705245\n","");
while(fahr<=upper)
{
celsius=5*(fahr-32)/9;
printf("%d\t%d\n",fahr,celsius);
fahr=fahr+step;
}
return 0;
}

运行结果:


 

任务2:

函数间的参数值单向传递

#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);
}


 

运行结果:

 

心得体会:

       第一次上机,我面对全英文版的开发环境,即使有老师提供的步骤,一片茫然。一开始,我没有把程序放入对应的文件中,导致我打完编码后,找不到文件,而无法运行;而且,输入程序的时候,我打的inculde忘了e,结果自然程序错误;有时候输代码,中英文之间的转换,全角和半角不记得改……好多问题,自己又是第一次上机,看有的同学都做完了,心里有急,就更加做不好了。不管怎么样,慢慢来吧,总会好的。

总结:

       一个程序至少有一个函数,main称为主函数;函数所有的语句都包括在一对花括号中。

 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: