回覆列表
  • 1 # 尋夢小老頭

    # include <stdio.h>

    # include <stdlib.h>

    # define PI 3.14159

    int main(void)

    {

    double r, c, s1, s2, v;

    printf("輸入圓的半徑:\n\a");

    scanf("%lf", &r);//這裡有變動,雙精度浮點型(double)輸入是用%lf

    c = PI * 2.0 * r;

    s1 = PI * r * r;

    s2 = 4.0 * s1;

    v = (4 * PI * r * r * r)/3.0;

    printf("周長 = %lf\n圓面積 = %lf\n球面積 = %lf\n球體積 = %lf\n", c, s1, s2, v);

    return 0;

    }

    想保留最後兩位:可以這樣

    # include <stdio.h>

    # include <stdlib.h>

    # define PI 3.14159

    int main(void)

    {

    double r, c, s1, s2, v;

    printf("輸入圓的半徑:\n\a");

    scanf("%lf", &r);//這裡有變動,雙精度浮點型(double)輸入是用%lf動 ,%.2lf

    c = PI * 2.0 * r;

    s1 = PI * r * r;

    s2 = 4.0 * s1;

    v = (4 * PI * r * r * r)/3.0;

    printf("周長 = %.2lf\n圓面積 = %.2lf\n球面積 = %.2lf\n球體積 = %.2lf\n", c, s1, s2, v);//這裡改動了,看看%.2lf

    return 0;

    }

  • 中秋節和大豐收的關聯?
  • 郭富城有《父子》,張學友有《男人四十》,黎明有《三更》,那劉德華有拿得出手影響力大的代表作嗎?