Answer to Question #225368 in C for MENSAH PAUL OSEI

Question #225368
The roots of the quadratic equation ax
1
Expert's answer
2021-08-11T14:11:54-0400

A program to calculate the roots of quadratic equation

#include <stdio.h>
#include <math.h>
int main()
{
  int a, b, c, d;
  double root1, root2;


  printf("Enter a, b and c where a*x*x + b*x + c = 0\n");
  scanf("%d%d%d", &a, &b, &c);


  d = b*b - 4*a*c;


  if (d < 0) { 
    printf("First root = %.2lf + i%.2lf\n", -b/(double)(2*a), sqrt(-d)/(2*a));
    printf("Second root = %.2lf - i%.2lf\n", -b/(double)(2*a), sqrt(-d)/(2*a));
  }
  else { 
    root1 = (-b + sqrt(d))/(2*a);
    root2 = (-b - sqrt(d))/(2*a);


    printf("First root = %.2lf\n", root1);
    printf("Second root = %.2lf\n", root2);
  }


  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS