C的圆柱计算器
今天從課堂上學(xué)的C
#include<stdio.h> #include<math.h> #define PI 3.141592654 void cal(int sel); double vol_ball(void); double vol_cylind(void); double vol_cone(void); int main() {int sel;while(1){printf("1-計(jì)算球體體積");printf("2-計(jì)算圓柱體體積");printf("3-計(jì)算圓錐體體積");printf(" 其他-退出程序運(yùn)行\(zhòng)n"); printf("請輸入計(jì)算命令:");scanf("%d",&sel);if(sel<1||sel>3)break;elsecal(sel);}return 0; }void cal(int sel) {switch(sel){case 1:printf("球體體積:%.2f\n",vol_ball()); break;case 2:printf("圓柱體體積:%.2f\n",vol_cylind()); break;case 3:printf("圓錐體體積:%.2f\n",vol_cone()); break;} }double vol_ball() {double r;printf("請輸入球體的半徑:");scanf("%lf",&r);return (4.0/3.0*PI*r*r*r); }double vol_cylind(){double r,h;printf("請輸入圓柱體的底圓半徑和高:");scanf("%lf%lf",&r,&h);return (PI*r*r*h); }double vol_cone(){double r,h;printf("請輸入圓錐體的底圓半徑和高:");scanf("%lf%lf",&r,&h);return (PI*r*r*h/3.0); }總結(jié)
- 上一篇: 2.excel导出-poi使用
- 下一篇: wemall单页化与wemall微分销