码迷,mamicode.com
首页 > 其他好文 > 详细

每日一例

时间:2019-11-06 23:10:23      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:int   clu   nbsp   表示   浮点   浮点数   对照表   打印   float   

#include <stdio.h>
/*当fathr = 0,20,...,300时,分别打印fahr华氏温度与celsius摄氏温度对照表*/
main()
{
 float fahr,celsius;
 int lower,upper,step;
 
 lower = 0;/*温度表的下限*/
 upper = 300;/*温度表的上限*/
 step = 20;/*步长*/
 
 fahr = lower;
 while(fahr <= upper)
 {
  celsius = 5* (fahr - 32) / 9;
  printf("%3.0f %6.1f\n",fahr, celsius);
  fahr = fahr + step;
 }
}
其中%6.1f  按浮点型打印,至少6个字符宽,小数点后有两位小数。%d表示按十进制整型打印;%f按浮点数打印;%o按八进制打印;%x按十六进制打印;%c表示字符;%s表示字符串;%%表示百分号(%)本身。

每日一例

标签:int   clu   nbsp   表示   浮点   浮点数   对照表   打印   float   

原文地址:https://www.cnblogs.com/TheFly/p/11809142.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!