Advertisement
daniv1

29.3

Oct 29th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.19 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. void swap(double *x1 , double *x2)
  5. {
  6.     double temp = *x1;
  7.     *x1 = *x2;
  8.     *x2 = temp;
  9. }
  10. double D(double a, double b,double c)
  11. {
  12.     return pow(b,2)-4*a*c;
  13. }
  14. double f1(double a,double b,double c)
  15. {
  16.     return pow(a,2) - 9*b*c;
  17. }
  18.  
  19. double f2(double x)
  20. {
  21.     return 4*x;
  22. }
  23.  
  24. double f3(double x1, double x2)
  25. {
  26.     return x2*sin(x1);
  27. }
  28. int main()
  29. {
  30.         double a, b, c, d;
  31.  
  32.         printf("Enter coefficients a, b and c: ");
  33.         scanf("%lf %lf %lf",&a, &b, &c);
  34.  
  35.         d = D(a,b,c);
  36.  
  37.  
  38.         if (d > 0)
  39.         {
  40.             double x1, x2;
  41.             x1 = (-b+sqrt(d))/(2*a);
  42.             x2 = (-b-sqrt(d))/(2*a);
  43.             if(x1>=x2)
  44.             {
  45.                 swap(&x1,&x2);
  46.             }
  47.  
  48.             printf("root1 = %.2lf and root2 = %lf;\n function = %lf",x1 , x2,f3(x1,x2));
  49.         }
  50.  
  51.         else if (d == 0)
  52.         {
  53.             double x = -b/(2*a);
  54.             printf("root1 = root2 = %lf;\nfunction = %lf",x,f2(x));
  55.         }
  56.  
  57.         // if roots are not real
  58.         else
  59.         {
  60.             printf("there are no real roots;\nfunction = %lf",f1(a,b,c));
  61.         }
  62.  
  63.         return 0;
  64.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement