jianghaoyu0129
/*利用循环计算n个圆柱体体积*/
#include<stdio.h>
int main(void)
{
    int i,n;
    double r,v,h;
    double cylinder(double r,double h);/*定义和调用函数cylinder(r,h)计算体积*/

    printf("enter n:");
    scanf("%d",&n);

    for(i=1;i<=n;i++){              /*for语句循环计算n个圆柱体体积*/
        printf("Enter r and h:\n");

        scanf("%lf%lf",&r,&h);

        if((r<=0)||(h<=0))/*或语句*/
        {
            printf("sorry");
        }
        else{
            v=cylinder(r,h);
            printf("V=%.3f\n",v);
        }
    }

    return 0;
}
double cylinder(double r,double h)
{
    double result;
    
    result=3.14*r*r*h;
    
    return result;
}

 

分类:

技术点:

相关文章:

  • 2022-02-03
  • 2021-12-19
  • 2021-12-22
  • 2022-02-21
  • 2021-12-11
  • 2021-07-16
  • 2021-07-13
  • 2022-03-01
猜你喜欢
  • 2021-12-01
  • 2022-02-15
  • 2022-02-20
  • 2022-01-21
  • 2022-02-22
  • 2022-01-29
相关资源
相似解决方案