題目: 輸入底面半徑radius和高height,輸出圓柱體的面積並保留三位數

範例輸入:

3.5 9

 
範例輸出:

274.889


分析:

圓柱體面積由上底面積、下底面積和側面積所組成,底面積為πr2

側面積為2πrh,以下為此題程式碼解答

#include <stdio.h>
#include <math.h>
int main(void)
{
    const float pi = acos(-1.0); 
    float area, radius, height, tmp1, tmp2;
    
    scanf("%f %f", &radius, &height );
    
    tmp1 = pi * radius * radius * 2;
    tmp2 = radius * pi * height * 2;
    area = tmp1 + tmp2;
    
    printf("%.3f", area);
}

 

arrow
arrow
    文章標籤
    圓柱體的表面積 C
    全站熱搜

    Will 發表在 痞客邦 留言(0) 人氣()