Advertisement
Guest User

Untitled

a guest
Nov 6th, 2013
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.07 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. // function declarations
  5. void Roots (float a,float b,float delta);
  6.  
  7. int main (void)                        
  8. {
  9.     //Local Declarations
  10.     float a,b,c,delta;
  11.  
  12.     printf("Input coefficient a.\n");
  13.     scanf("%f", &a);
  14.     printf("Input coefficient b.\n");
  15.     scanf("%f", &b);
  16.     printf("Input coefficient c.\n");
  17.     scanf("%f", &c);
  18.     printf("\nThe equation is : %0.2fx^2 + %0.2fx + %0.2f\n\n", a, b, c);
  19.  
  20.     delta = (b*b) - (4.0 * a * c);
  21.  
  22.     if (delta > 0){
  23.          printf("There are two distinct roots.\n\n");
  24.          Roots(a,b,delta);
  25.     }else if (delta == 0) {
  26.          printf("This equation has repeated roots\n\n");
  27.          Roots(a,b,delta);
  28.     }else if (delta < 0.0){
  29.          printf("There are no real roots\n");
  30.     }
  31.     return 0;
  32. }
  33.  
  34. void Roots (float a,float b,float delta)
  35. {
  36.     float xOne;
  37.     float xTwo;
  38.     float deltaRoot;
  39.  
  40.     deltaRoot = sqrt(delta);
  41.     xOne = (-b + deltaRoot) / (2*a);
  42.     xTwo = (-b - deltaRoot) / (2*a);
  43.     printf("%.2f , ", xOne);
  44.     printf("%.2f", xTwo);
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement