• 实验二 用C语言编写简单程序


    #include<stdio.h>
    int main(void)
    {
        double r,s;
        double cylinder(double r);
        
        printf("Enter r:");
        scanf("%lf",&r);
    
        if(r<=0){
            printf("输入错误");
        }
        else if(r>0){
            s=3.1415926*r*r;
            printf("s=%.3f
    ",s);
        }
        return 0;
    }
    #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:");
    		scanf("%lf%lf",&r,&h);
    		if((r<=0)||(h<=0)){
    			printf("输入错误,重新输入");
    		}
    		else{
                v=cylinder(r,h);
    			printf("v=%.3f
    ",v);
    		}
    	}
    	return 0;
    }
    
    double cylinder(double r,double h)
    {
    	double result;
    	result=3.1415926*r*r*h;
    	return result;
    }
    #include<stdio.h>
    int main(void)
    {
    	
    	int i,n;
    	double x,y;
    
    	printf("Enter n:");
    	scanf("%d",&n);
    
    	
    	for(i=1;i<=n;i++){
    		printf("Enter x:");
    		scanf("%lf",&x);
    		if(x<=0){
    		printf("输入错误,重新输入");
    		}
    		else if(x<=50){
    			y=0.53*x;
    			printf("y=%lf
    ",y);
    		}
    		else{
    			y=(x-50)*0.58+50*0.53;
    			printf("y=%lf
    ",y);
    		}
    	}
    	return 0;
    }
    #include<stdio.h>
    int main(void)
    {
        
        int i,m;
        double x,y;
        double fact(double x);
        double cylinder(double x);
    
        printf("Enter m:");
        scanf("%d",&m);
    
        
        for(i=1;i<=m;i++){
            printf("Enter x:");
            scanf("%lf",&x);
            if(x<=0){
            printf("输入错误,重新输入");
            }
            else if(x<=50){
                y=fact(x);
                printf("y=%lf
    ",y);
            }
            else{
                y=cylinder(x);
                printf("y=%lf
    ",y);
            }
        }
        return 0;
    }
    double fact(double x)
    {
        double result;
        result=0.53*x;
        return result;
    }
    double cylinder(double x)
    {
        double result;
        result=0.53*50+(x-50)*0.58;
        return result;
    }
  • 相关阅读:
    PHP strcmp,strnatcmp,strncmp函数的区别
    PHP echo,print_r(expression),var_dump(expression)区别
    PHP包含文件语句include和require的区别
    PHP魔术变量__METHOD__,__FUNCTION__的区别
    解决margin重叠的问题
    冒牌、选择、插入排序算法
    == 和 === 的区别
    Javascript常见浏览器兼容问题
    浏览器常见兼容性问题汇总
    JS中replace()用法举例
  • 原文地址:https://www.cnblogs.com/liyang1995/p/3373384.html
Copyright © 2020-2023  润新知