C语言之double

 1 #include<stdio.h>
 2 
 3 int main(void)
 4 {
 5     printf("请分别输入身高的英尺和英寸,""如输入\"5 7\"表示5英尺7英寸:");
 6 
 7     double foot;    //双精度浮点数
 8     double inch;
 9 
10     scanf_s("%lf %lf", &foot, &inch);    //double型变量,输入时用%lf
11 
12     printf("身高是%f米。\n", (foot + inch / 12) * 0.3048);
13 
14     return 0;
15 }

 

 1 #include<stdio.h>
 2 
 3 int main(void)
 4 {
 5     int a, b;
 6 
 7     scanf_s("%d %d", &a, &b);
 8 
 9     double c = ((double)a + (double)b) / 2.0;    //强制转换数据类型
10 
11     printf("%d和%d的平均值=%f\n", a, b, c);
12 
13     return 0;
14 }

 

posted @ 2019-10-29 09:05  jason2018  阅读(997)  评论(0编辑  收藏  举报