Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. void findRoots(int a, int b, int c)
  2. {
  3. // If a is 0, then equation is not quadratic, but
  4. // linear
  5. if (a == 0)
  6. {
  7. xil_printf("Invalid");
  8. return;
  9. }
  10.  
  11. int d = b*b - 4*a*c;
  12. double sqrt_val = sqrt(abs(d));
  13.  
  14. if (d > 0)
  15. {
  16. xil_printf("Roots are real and different: %f\n%f\n", (double)(-b + sqrt_val)/(2*a)
  17. , (double)(-b - sqrt_val)/(2*a));
  18. }
  19. else if (d == 0)
  20. {
  21. xil_printf("Roots are real and same %f\n", -(double)b / (2*a));
  22. }
  23. else // d < 0
  24. {
  25. xil_printf("Roots are complex %f + i%f\n%f - i%f\n", -(double)b / (2*a),sqrt_val
  26. ,-(double)b / (2*a), sqrt_val);
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement