Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.81 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. float SoulSquare (float a, float b, float c, float *x1, float *x2);
  5.  
  6. int main()
  7. {
  8.     float a,b,c,x1,x2;
  9.     printf ("A = ");
  10.     scanf ("%f",&a);
  11.     printf ("B = ");
  12.     scanf ("%f",&b);
  13.     printf ("C = ");
  14.     scanf ("%f",&c);
  15.  
  16.     int nRoots =  SoulSquare(a, b, c, &x1, &x2);
  17.    
  18.     printf("nRoots = %d\n", nRoots);
  19.  
  20.     if (nRoots > 0)
  21.     {
  22.         if (nRoots == 1)
  23.         {
  24.             printf("x1 = %f\n", x1);
  25.         }
  26.         else
  27.         {
  28.             printf("x1 = %f\n", x1);
  29.             printf("x2 = %f\n", x2);
  30.         }
  31.     }
  32.     else
  33.     {
  34.         printf("No roots!");
  35.     }
  36. }
  37.  
  38.  
  39. float SoulSquare (float a, float b, float c, float *x1, float *x2)
  40. {
  41.     float D;
  42.     D = b*b - 4*a*c;
  43.  
  44.     *x1 = (-b + sqrt (D))/2*a;
  45.     *x2 = (-b - sqrt (D))/2*a;
  46.  
  47.     if (D < 0)
  48.     {
  49.         return 0;
  50.     }
  51.     if (D == 0)
  52.     {
  53.         return 1;
  54.     }
  55.     if (D > 0)
  56.     {
  57.         return 2;
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement