5 solutions

  • 1
    @ 2023-9-30 20:02:29
    #include <stdio.h>
    #include <math.h>
    int main()
    {
    	double a,b,c;
    	scanf("%lf %lf %lf",&a,&b,&c);
    	double t=b*b-4*a*c;
    	double x1=(-b+sqrt(t))/(2*a);
    	double x2=(-b-sqrt(t))/(2*a);
    	while(t>=0){
    		if(t==0)
    			printf("x1=x2=%.5f",x1);
    		else//t>0
    		{
    			if(x1<x2)
    				printf("x1=%.5f;x2=%.5f",x1,x2);
    			else//x2<x1
    				printf("x1=%.5f;x2=%.5f",x2,x1);
    		}
    		return 0;
    	}	
    	printf("No answer!");
    	return 0;
    }
    
    • 0
      @ 2024-7-28 21:20:47
      #include<iostream>
      #include<cmath>
      using namespace std;
      int main()
      {
          double a,b,c,x1,x2;
          scanf("%lf %lf %lf",&a,&b,&c);
          x1 = (-b + sqrt(b * b - 4 * a * c)) / (2 * a);
          x2 = (-b - sqrt(b * b - 4 * a * c)) / (2 * a);
          double res = b * b - 4 * a * c;
          if(res < 0){
              printf("No answer!");
          }else 
              if(res == 0){
                  printf("x1=x2=%.5lf",x1);
              }else
                  if(res > 0){
                      if(x1 > x2){
                          swap(x1,x2);
                      }
                      printf("x1=%.5lf;x2=%.5lf",x1,x2);
                  }else printf("No answer!");
          return 0;
      }
      
      • 0
        @ 2023-11-17 16:34:53
        #include <stdio.h>
        #include <math.h> //要用到开平方和平方
        int main()
        {
            double a, b, c;
            scanf("%lf %lf %lf", &a, &b, &c);/*现在只能说是一元二次型方程, 因为a的值未知*/
            double d = pow(b, 2) - 4 * a * c; /*d就是那个德尔塔但是没开根号*/
            if (d < 0 || a == 0) /*如果a等于零那么就是一元一次方程*/
            {
                printf("No answer!");
            }
            else if (d >= 0)
            {
                double x1 = (0 - b + sqrt(d)) / (2 * a);
                double x2 = (0 - b - sqrt(d)) / (2 * a);
                if (x1 < x2)
                {
                    printf("x1=%.5f;x2=%.5f", x1, x2);
                }
                else if (x1 > x2)
                {
                    printf("x1=%.5f;x2=%.5f", x2, x1);
                }
                else if (x1 == x2)
                {
                    printf("x1=x2=%.5f", x1);
                }
            }
            return 0;
        }
        
        • 0
          @ 2023-10-18 10:54:33
          #include <stdio.h>
          #include <math.h>
          int main()
          {
              double a,b,c,d,x1,x2,max,min;
              scanf("%lf %lf %lf",&a,&b,&c);
              d=b*b-4*a*c;x1=(-b+sqrt(d))/(2*a);x2=(-b-sqrt(d))/(2*a);
              if(x1==x2){printf("x1=x2=%.5f",x1);}else{
              if(x1<x2){max=x2;min=x1;}else{max=x1;min=x2;};
              if(d<0){printf("No answer!");};
              if(d>0){printf("x1=%.5f;x2=%.5f",min,max);};}
              return 0;
          }
          
          • 0
            @ 2023-10-6 11:48:09
            #include<math.h>
            int main()
            {
                double a,b,c,d,x1,x2,e;
                scanf("%lf %lf %lf",&a,&b,&c);
                d=b*b-4*a*c;
                if(d<0){
                    printf("No answer!");
                }else{
                    if(d==0){
                        x1=x2=(-b)/(2*a);
                        printf("x1=x2=%.5f",x1);
                    }else{
                        e=sqrt(d);
                        x1=(-b+e)/(2*a);
                        x2=(-b-e)/(2*a);
                       if(x1<x2){
                        printf("x1=%.5f;x2=%.5f",x1,x2);
                        }else{
                            printf("x1=%.5f;x2=%.5f",x2,x1);
                            }
                    }
                }return 0;
            }
            
            • 1

            Information

            ID
            6735
            Time
            1000ms
            Memory
            128MiB
            Difficulty
            9
            Tags
            (None)
            # Submissions
            714
            Accepted
            72
            Uploaded By