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;
}

 

分类:

技术点:

相关文章:

  • 2021-10-31
  • 2021-04-05
  • 2021-12-18
  • 2021-09-17
  • 2021-10-16
  • 2021-08-28
  • 2021-12-27
  • 2021-08-11
猜你喜欢
  • 2021-11-10
  • 2021-08-28
  • 2021-11-02
  • 2021-11-10
  • 2021-08-28
  • 2021-11-10
  • 2018-04-23
相关资源
相似解决方案