Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void findRoots(int a, int b, int c)
- {
- // If a is 0, then equation is not quadratic, but
- // linear
- if (a == 0)
- {
- xil_printf("Invalid");
- return;
- }
- int d = b*b - 4*a*c;
- double sqrt_val = sqrt(abs(d));
- if (d > 0)
- {
- xil_printf("Roots are real and different: %f\n%f\n", (double)(-b + sqrt_val)/(2*a)
- , (double)(-b - sqrt_val)/(2*a));
- }
- else if (d == 0)
- {
- xil_printf("Roots are real and same %f\n", -(double)b / (2*a));
- }
- else // d < 0
- {
- xil_printf("Roots are complex %f + i%f\n%f - i%f\n", -(double)b / (2*a),sqrt_val
- ,-(double)b / (2*a), sqrt_val);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement