面积和体积

求圆周长、圆面积、圆柱表面积、圆柱体积,输出计算结果,取小数点后2位数字。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include<stdio.h>
#define PAI 3.14159265358979
int main()
{
    float a, b, c, d, h, r;
    printf("Please enter the redius of a circle: \n");
    scanf("%f", &r);
    printf("Please enter the height of a cylinder: \n");
    scanf("%f", &h);
    a = 2 * PAI * r;
    b = PAI * r * r;
    c = 2 * b + a * h;
    d = b * h;
    printf("The perimeter of the circle is: %.2f\n", a);
    printf("The area of the circle is: %.2f\n", b);
    printf("The surface area of the cylinder is: %.2f\n", c);
    printf("The volume of the cylinder is: %.2f\n", d);
    return 0;
}