1 条题解

  • 0
    @ 2024-10-7 19:11:40
    #include <stdio.h>
    #include <math.h>
    int main()
    {
    	int a = 0;
    	int b = 0;
    	int c = 0;
    	double d = 0.0;
    	double f = 0.0;
    	double r1 = 0.0;
    	double r2 = 0.0;
    	scanf("%d %d %d", &a, &b, &c);
    	d = pow(b, 2) - 4 * a * c;
    	if (a == 0)
    	{
    		if (b == 0)
    		{
    			if(b==0&&c!=0)
    			printf("no solution");
    			if(b==0&&c==0)
    			printf("%.6f",(float)c);
    		}
    		else printf("%.6f", (float)-1.0*c / b);
    	}
    	else
    	{
    		if (d < 0)
    			printf("no solution");
    		if (d > 0)
    		{
    			f = sqrt(d);
    			r1 = 1.0*(-b - f) / (2 * a);
    			r2 = 1.0*(-b + f) / (2 * a);
    			if (r1 > r2)
    			{
    				printf("%.6f %.6f", (float)r2, (float)r1) ;
    			}
    			else if (r1 < r2)
    			{
    				printf("%.6f %.6f", (float)r1, (float)r2) ;
    			}
    		}
    		if (d == 0)
    		{
    			printf("%.6f %.6f",-1.0*b/(2*a),-1.0*b/(2*a));
    		}
    	}
    	return 0;
    }
    

    *注: 1.如果出现"-inf"的情况,这个代表该数为负无穷大,很有可能出现了x/0的情况 2.注意"有解"的情况只需输出一次 3.注意考虑各变量=0的情况

    信息

    ID
    22
    时间
    1000ms
    内存
    512MiB
    难度
    9
    标签
    递交数
    1457
    已通过
    92
    上传者