求圆柱体侧面积,底面周长,表面积和体积

img


试了很长时间都没试出来,实在搞不懂这个expected primary-expression before“=” token要说什么

这个错误应该是因为# define PI = 3.14 里的等号, 去掉等号改为 # define PI 3.14 就可以了;

然后把C, Sb, s2, v这四个变量的数据类型改为double类型,因为运算中有小数参与,所以如果要保存小数位的结果,可以把这四个变量的数据类型改为double。

修改如下:

参考链接:


https://easylearn.baidu.com/edu-page/tiangong/bgkdetail?id=1ad2b82aed630b1c59eeb544&fr=search

https://blog.csdn.net/wswnbtfkpuqw/article/details/124678372

https://zhidao.baidu.com/question/1456410556366346220.html

https://blog.csdn.net/chenminghe271/article/details/6658201



#include <stdio.h>
#include <math.h>
#define PI  3.14   // 去除等号 https://blog.csdn.net/qq_42379345/article/details/81226476

int main(void){
    
    double r,h;
    double C,Sb,s2,v;
    scanf("%lf %lf",&r,&h);
//    printf("r=%f,h=%f\n",r,h);
    
    // https://easylearn.baidu.com/edu-page/tiangong/bgkdetail?id=1ad2b82aed630b1c59eeb544&fr=search
    // https://blog.csdn.net/wswnbtfkpuqw/article/details/124678372
    // https://zhidao.baidu.com/question/1456410556366346220.html
    // https://blog.csdn.net/chenminghe271/article/details/6658201 
    C=2*PI*r;  // 求对应圆的周长 
    Sb=PI*r*r;  // 求对应圆的面积 
    s2=2*PI*r*r*h;  // 如果这个是求对应圆柱体的测面积,则去除一个r 
    v=4.0*PI*r*r*r/3;  // 求对应球的体积 
    
    printf("%.2lf %.2lf\n",C,Sb);
    printf("%.2lf %.2lf\n",s2,v);
    
    return 0;
} 

img