【C语言及程序设计】项目1-4-2-4:计算圆柱体表面积

 1 /*圆柱体表面积.cpp:  
 2 问题描述:输入圆柱体的半径r和高h,输出圆柱体的表面积s。提示:π值直接写3.1415926 
 3 */  
 4   
 5 #include "stdafx.h"  
 6   
 7   
 8 int main()  
 9 {  
10     float r, h, A;  
11     printf("Input the radius and height of the cylinder.\n");  
12     scanf_s("%f \n %f", &r, &h);  
13   
14     A = 2 * 3.1415926f * r * h + 2 * 3.1415926f * r * r;  
15   
16     printf("\n The surface area of the cylinder is %f", A);  
17   
18   
19     return 0;  
20 }  

感想:

1.函数 printf 和 scanf 结构非常类似:

printf(“输出格式”,变量1,……,变量n);

scanf(“输出格式”,&变量1,……,&变量n);

目前所能看出,二者语法的区别在于变量前的ampersand。(这是为什么?

2.

3.1415926f  

若丢掉f,则编译器默认为double类型数据,可能造成数据丢失。(具体是怎样的丢失?)

 

猜你喜欢

转载自www.cnblogs.com/miyazakehime/p/9104371.html