/*圆柱体表面积.cpp:
问题描述:输入圆柱体的半径r和高h,输出圆柱体的表面积s。提示:π值直接写3.1415926
*/
#include "stdafx.h"
int main()
{
float r, h, A;
printf("Input the radius and height of the cylinder.\n");
scanf_s("%f \n %f", &r, &h);
A = 2 * 3.1415926f * r * h + 2 * 3.1415926f * r * r;
printf("\n The surface area of the cylinder is %f", A);
return 0;
}
感想:
1.函数 printf 和 scanf 结构非常类似:
printf(“输出格式”,变量1,……,变量n);
scanf(“输出格式”,&变量1,……,&变量n);
目前所能看出,二者语法的区别在于变量前的ampersand。(这是为什么?)
2.注意
3.1415926f
若丢掉f,则编译器默认为double类型数据,可能造成数据丢失。(具体是怎样的丢失?)