第二次上机指导

 第二次上机指导

任务1:显示美元和人民币的汇率

实验内容:编写一个“显示美元和人民币的汇率”C 程序
实验目的:进一步掌握简单 C 程序的编写和运行的过程
说明:假设100 美元=621 人民币,程序显示100、200、300….1000 美元与人民币汇率表

我的程序


void main();
{int a,b;
a=100;
while(a<=1000)
{b=621*a;
a=a+100;
printf("%d美元=%d人民币\n",b,a);

}
 return 0;
}

运行结果

···················································任务分割线···································································································


任务2:了解int 和float 变量类型
实验内容:修改”华氏温度与摄氏温度对照表”

实验目的:了解“同一变量”定义不同数据类型,如何影响程序运行结果

第一次程序

;int main()
{ int f;
  int c;

  int lower=0;
  int upper=300;
  int step=20;
  f=lower;
  printf("李乔峰,38\n");
  while (f<=upper)
  {c=(5/9)*(f-32);
  printf("%d\t%d\n",f,c);
  f=f+step;
  }
}

运行结果

修改后的程序

;int main()
{
  float f;
  float c;

  float lower=0;
  float upper=300;
  float step=20;
  f=lower;
  printf("李乔峰,38\n");
  while (f<=upper)
  {
  c=(5.0/9.0)*(f-32.0);
  printf("%f\t%f\n",f,c);
  f=f+step;
  }
  return 0;
}

运行结果

···········································任务分割线····································································································

小结

今天我了解了INT和FLOAT的区别

INT对应的是%d

而FLOAT对应的是%f

勿忘

猜你喜欢

转载自blog.csdn.net/l624547260/article/details/8676047
今日推荐