课时练习

#include<stdio.h>
int main(void)
{
    int i,n;
    double r,h,v;
    double cylinder(double r,double h);
    printf("Enter n:");
    scanf("%d",&n);
    for(i = 1;i <= n;i++){
        printf("Enter r and h:\n");
        scanf("%lf%lf",&r,&h);
        v = cylinder(r,h);
        printf("v = %.2f\n",v);
        if((r <= 0)||(h <= 0))
        {
            printf("Enter error!\n");
        }
        else{
            v=cylinder(r,h);
            printf("v=%.2f\n",v);
        }
    }
    return 0;
}
double cylinder(double r,double h)
{
    double result;
    {
        result = 3.14 * r * r *h;
    }
    return result;
}

 

posted @ 2013-10-17 10:00  shadowtly  阅读(131)  评论(0)    收藏  举报