Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <math.h>
- int raizes (float a, float b, float c, float * x1, float * x2);
- int main()
- {
- float a, b, c, r1, r2;
- int num;
- scanf("%f %f %f", &a, &b, &c);
- num = raizes(a, b, c, &r1, &r2);
- if(num == 0)
- printf("Nenhuma raiz real\n");
- else if(num == 1)
- {
- printf("X1 = X2 = %f\n", r1);
- }
- else
- {
- printf("X1 = %f\n", r1);
- printf("X2 = %f\n", r2);
- }
- getch();
- }
- int raizes(float a, float b, float c, float * x1, float * x2)
- {
- float delta = pow(b, 2) - 4 * a * c;
- if(delta < 0)
- return 0;
- else if(delta == 0)
- {
- *x1 = (b * -1 + sqrt(delta)) / (2 * a);
- return 1;
- }
- else
- {
- *x1 = (b * -1 + sqrt(delta)) / (2 * a);
- *x2 = (b * -1 - sqrt(delta)) / (2 * a);
- return 2;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement