第一次c程序设计上机报告
2013-03-12 13:08
169 查看
第一次c程序设计上机报告
姓名:严浩峰 学号:120705216 班级:12电子信息工程2班
任务一:创建一个基本程序
实验内容:编写一个“显示华氏温度与摄氏温度对照表”C程序
实验目的:掌握C语言开发工具,掌握简单C程序的编辑,编译,连接和运行的一般过程
我的程序:
//***********************************
//对fahr=0,20,...300
//打印华氏温度与摄氏温度对照表
//code by 严浩峰 120705216 3.8
//************************************
#include<stdio.h>
int main()
{
int fahr,celsius;
int lower,upper,step;
lower =0; /*温度表的下限*/
upper=300; /*温度表的上限*/
step=20; /*步长*/
fahr=lower;
printf("姓名,学号\n","");
while(fahr<=upper){
celsius=5*(fahr-32)/9;
printf("%d %d\n", fahr,celsius);
fahr=fahr+step;
}
return 0;
}
程序运行效果截图:
修改代码,将printf("%d %d\n", fahr,celsius);改为printf("%d\t %d\n", fahr,celsius);
修改代码后,程序运行效果截图:
···································································
······················································································任务分割线············································································
任务二:进一步熟悉C程序编写的一般过程。
实验内容:运行作业“例 6-3 ”程序
实验目的:加深理解C程序的编辑,编译,连接和运行的一般过程
/*源程序: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);
}
运行程序效果截图:
------------------------------------------------任务分割线------------------------------------------------
第一次C程序设计上机体会:
体会:过程有点麻烦,很容易出错,但是做完以后还是会有点充实的感觉
知识点总结:
一个程序至少要有一个函数,mian函数常称为主函数:
函数中所有语句都包括在一堆花括号中:
各语句间用“;”结束
有两种注释方法1.“/*注释内容*/” 2.“//注释内容”
姓名:严浩峰 学号:120705216 班级:12电子信息工程2班
任务一:创建一个基本程序
实验内容:编写一个“显示华氏温度与摄氏温度对照表”C程序
实验目的:掌握C语言开发工具,掌握简单C程序的编辑,编译,连接和运行的一般过程
我的程序:
//***********************************
//对fahr=0,20,...300
//打印华氏温度与摄氏温度对照表
//code by 严浩峰 120705216 3.8
//************************************
#include<stdio.h>
int main()
{
int fahr,celsius;
int lower,upper,step;
lower =0; /*温度表的下限*/
upper=300; /*温度表的上限*/
step=20; /*步长*/
fahr=lower;
printf("姓名,学号\n","");
while(fahr<=upper){
celsius=5*(fahr-32)/9;
printf("%d %d\n", fahr,celsius);
fahr=fahr+step;
}
return 0;
}
程序运行效果截图:
修改代码,将printf("%d %d\n", fahr,celsius);改为printf("%d\t %d\n", fahr,celsius);
修改代码后,程序运行效果截图:
···································································
······················································································任务分割线············································································
任务二:进一步熟悉C程序编写的一般过程。
实验内容:运行作业“例 6-3 ”程序
实验目的:加深理解C程序的编辑,编译,连接和运行的一般过程
/*源程序: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);
}
运行程序效果截图:
------------------------------------------------任务分割线------------------------------------------------
第一次C程序设计上机体会:
体会:过程有点麻烦,很容易出错,但是做完以后还是会有点充实的感觉
知识点总结:
一个程序至少要有一个函数,mian函数常称为主函数:
函数中所有语句都包括在一堆花括号中:
各语句间用“;”结束
有两种注释方法1.“/*注释内容*/” 2.“//注释内容”