1 条题解

  • 0
    @ 2025-12-5 16:55:34

    C :

    #include<stdio.h>
    #include<math.h>
    int main()
    {
        float a,b,c,d;
        scanf("%f%f%f",&a,&b,&c);
        d=(a+b+c)/2.;
        d=sqrt(d*(d-a)*(d-b)*(d-c));
        printf("%.3f",d);
    }
    

    C++ :

    #include<stdio.h>
    #include<math.h> 
    int main()
    {
        double a,b,c,s,p;
        while(scanf("%lf %lf %lf",&a,&b,&c)!=EOF)
        {
            p=(a+b+c)/2.0000;
            p=p*(p-a)*(p-b)*(p-c);
            s=sqrt(p); 
            printf("%.3lf\n",s); 
        } 
    } 
    
    

    Java :

    import java.util.Scanner;
    
    public class Main {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		
    		Scanner input = new Scanner(System.in);
    		
    		double a = input.nextDouble();
    		double b = input.nextDouble();
    		double c = input.nextDouble();
    		double s = (a + b + c)/2.0;
    		double area = Math.sqrt(s*(s-a)*(s-b)*(s-c));
    		System.out.printf("%.3f",area);
    		input.close();
    	}
    	
    	
    
    }
    
    

    Python :

    a = map(lambda x:float(x), raw_input().split())
    x = sum(a)/2
    
    print "%.3f"%((x*(x-a[0])*(x-a[1])*(x-a[2]))**0.5)
    
    • 1

    C语言程序设计教程(第三版)课后习题9.3

    信息

    ID
    2022
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    (无)
    递交数
    0
    已通过
    0
    上传者