-
Function not working
This program should return the number of roots of a 2nd degree polynomial, but it always returns 2 roots, whatever coefficients I put.
Whatīs wrong??
Itīs in spanish, so RAICES=ROOTS, and disc means the discriminant of the equation (b^2 - 4*a*c).
Thanks in advance.
Code:
#include <stdio.h>
#include <stdlib.h>
int raices (int a, int b, int c)
{
int x,y,z,disc;
disc=((y*y)-(4*x*z));
if (disc<0)
return 0;
if(disc==0)
return 1;
if(disc>0)
return 2;
}
int main()
{
int a,b,c;
printf("a= ");
scanf("%d",&a);
printf("b= ");
scanf("%d",&b);
printf("c= ");
scanf("%d",&c);
printf("El polinomio tiene %d raices\n",raices(a,b,c));
system("PAUSE");
return 0;
}
-
> disc=((y*y)-(4*x*z));
Try it with a,b,c and not x,y,z
-
excellent!
Now I must think why it doesnīt work the other way...
thanks!!!!