1 条题解

  • 0
    @ 2024-12-24 10:06:15

    C :

    #include<stdio.h>
    #include<math.h>
    int main()
    {
    	double a,b,c;
    	void root(double a,double b,double c);
    	scanf("%lf%lf%lf",&a,&b,&c);
    	if(a!=0.0) root(a,b,c);
    	getchar();
    	getchar();
    	return 0;
    }
    void root(double a,double b,double c)
    {
    	double x,root1,root2;
    	if (b*b-4*a*c>=0)
    	{
    		x=sqrt(b*b-4*a*c);
    		root1=(-b+x)/(2*a);
    		root2=(-b-x)/(2*a);
    		printf("r1=%7.2f\n",root1);
    		printf("r2=%7.2f\n",root2);
    	}
    	else printf("No real roots!\n");
    }
    

    C++ :

    #include <cstdio>
    #include <cmath>
    int main (void)
    {
    	double a,b,c,r1,r2;
    	scanf("%lf%lf%lf",&a,&b,&c);
    	if((b*b-4*a*c)<0){
    		printf("No real roots!\n");
    	}else {
    		r1=(-b+sqrt(b*b-4*a*c))/(2*a);
    		r2=(-b-sqrt(b*b-4*a*c))/(2*a);
    		printf("r1=%7.2f\nr2=%7.2f\n",r1,r2);
    	}
    	return 0;
    }
    
    • 1

    信息

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