汪云峰 班级:电子信息工程一班 学号:120705116
-------------------------------------------------------分割线-----------------------------------------------------
任务 1:显示美元和人民币的汇率
实验内容:编写一个“显示美元和人民币的汇率”C程序
实验目的:进一步掌握简单C程序的编写和运行过程
编程语言:
//******************
//Exchange Rate Tables
//code by Cloud
//******************
#include<stdio.h>
int main()
{
int fahr,dollars;
int first,last,step;
first=100;
last=1000;
step=100;
fahr=first;
printf("汪云峰,120705116\n","");
while(fahr<=last){
dollars=(6.21)*fahr;
printf("%d\t%d\n",fahr,dollars);
fahr=fahr+step;
}
return 0;
}
运行程序:
![](https://img-my.csdn.net/uploads/201303/15/1363355180_6742.png)
-------------------------------------------------------分割线-----------------------------------------------------
任务 2:了解 int和float变量类型
实验内容:修改“华氏温度与摄氏温度对照表”
实验目的:了解“同一变量”定义不同数据类型,如何影响程序运行结果
编程语言:
//********************
//code by Cloud
//********************
#include<stdio.h>
int main()
{
int f;
int c;
int lower=0;
int upper=300;
int step=20;
f=lower;
printf("汪云峰,120705116\n","");
while(f<=upper)
{
//**********************************
//摄氏与华氏温度转换公式
//c=(5/9)(f-32)
//**********************************
c=(5/9)*(f-32);
printf("%d\t%d\n",f,c);
f=f+step;
}
return 0;
}
运行程序:
![](https://img-my.csdn.net/uploads/201303/15/1363355408_5455.png)
修改代码:
//********************
//code by Cloud
//********************
#include<stdio.h>
int main()
{
float f;
float c;
float lower=0;
float upper=300;
float step=20;
f=lower;
printf("汪云峰,120705116\n","");
while(f<=upper)
{
//**********************************
//摄氏与华氏温度转换公式
//c=(5/9)(f-32)
//**********************************
c=(5.0/9.0)*(f-32.0);
printf("%f\t%f\n",f,c);
f=f+step;
}
return 0;
}
运行程序:
![](https://img-my.csdn.net/uploads/201303/15/1363355474_1488.png)
-------------------------------------------------------分割线-----------------------------------------------------
上机心得:
int表示整型 float表示单精度类型