课堂实验(圆柱体积)

#include<stdio.h>
int main()
{
    int i,n;
    double r,v,h;
    double cylinder(double r,double h);

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

    for(i=1;i<=n;i++){
        printf("Enter r and h:");

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

        if((r<=0)||(h<=0))
        {
            printf("输入错误,重新输入\n");
        }
        else{
            v=cylinder(r,h);
            printf("V=%.3f\n",v);
        }
    }

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

 

 

posted @ 2013-10-14 09:50  执于一念  阅读(167)  评论(0编辑  收藏  举报