Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- float SoulSquare (float a, float b, float c, float *x1, float *x2);
- int main()
- {
- float a,b,c,x1,x2;
- printf ("A = ");
- scanf ("%f",&a);
- printf ("B = ");
- scanf ("%f",&b);
- printf ("C = ");
- scanf ("%f",&c);
- int nRoots = SoulSquare(a, b, c, &x1, &x2);
- printf("nRoots = %d\n", nRoots);
- if (nRoots > 0)
- {
- if (nRoots == 1)
- {
- printf("x1 = %f\n", x1);
- }
- else
- {
- printf("x1 = %f\n", x1);
- printf("x2 = %f\n", x2);
- }
- }
- else
- {
- printf("No roots!");
- }
- }
- float SoulSquare (float a, float b, float c, float *x1, float *x2)
- {
- float D;
- D = b*b - 4*a*c;
- *x1 = (-b + sqrt (D))/2*a;
- *x2 = (-b - sqrt (D))/2*a;
- if (D < 0)
- {
- return 0;
- }
- if (D == 0)
- {
- return 1;
- }
- if (D > 0)
- {
- return 2;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement