Advertisement
godsqueezy

Untitled

Feb 28th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.09 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <windows.h>
  4.  
  5. void RootsofQuadratic(int a, int b, int c)
  6. {
  7.  
  8.     if (a == 0)
  9.     {
  10.         printf("The value of a cannot be 0");
  11.         return;
  12.     }
  13.  
  14.     int d = b*b - 4*a*c;
  15.     double SquarerootDescriminant = sqrt(abs(d));
  16.  
  17.     if (d > 0)
  18.     {
  19.         printf("The Roots are Real in Nature n");
  20.         printf("%fn%f",(double)(-b + SquarerootDescriminant)/(2*a)
  21.             , (double)(-b - SquarerootDescriminant)/(2*a));
  22.     }
  23.     else if (d == 0)
  24.     {
  25.         printf("The roots are equal and Real in Nature n");
  26.         printf("%f",-(double)b / (2*a));
  27.     }
  28.     else // d < 0
  29.     {
  30.         printf("The Roots are Complex in Nature n");
  31.         printf("%f + i%fn%f - i%f", -(double)b / (2*a),SquarerootDescriminant
  32.             ,-(double)b / (2*a), SquarerootDescriminant);
  33.     }
  34. }
  35. int main()
  36. {
  37.     int a;
  38.     int b;
  39.     int c;
  40.    printf("For a quadratic equation of form ax2 + bx + c = 0 enter values of a, b, cn");
  41.    scanf("%d%d%d", &a, &b, &c);  /*Asking for input*/
  42.     RootsofQuadratic(a, b, c);
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement