Hey, i'm trying to create a program that factorises quadratics but i'm having trouble with a certain aspect.
At the moment it factorises if a, b, and c are positive, and factorises if a and c are positive with b negative.
Now i'm trying to do the last one where a is positive, c is negative, and b is positive/negative depending on the numbers used but i'm struglling so i decided to add in some output statements to see if i'm getting the desired results but i either get nothing or garbage results.
EDIT** Sorry, to be more specific... I'm using arrays to hold the factors of C which i then use to add/subtract to get B but when i try and cycle through the array outputting each element i get nothing or garbage results
So i guess a good starting question would be, can arrays hold negative integers?
*scratches head*... umm... could you post some code?
What do you mean by quadratics? Something like ax^2+bx+c = a(x-(-b+sqrt(b*b-4*a*c))/(2*a) ) (x-(-b-sqrt(b*b-4*a*c))/(2*a) ) ( http://en.wikipedia.org/wiki/Quadratic_equation ) or do you mean something more complicated?
Some notes: this method requires that a be equal to 1!
The factorization will work only if your equation has rational solutions. Otherwise it will fail to factor your quadratic.
The formula is absolutely the same whether you use positive or negative numbers. If in factors you already precomputed the positive divisors of c, it will suffice simply to enlarge factors by adding the negative divisors of c.
@ tition
... to them first two notes I know dont worry, i've actually got a switch case set up so that the quadratic will be hadnled differently in each case, and I only wanted rational solutions so that they could be putput as I have shown in my last post.
The problem is that when I send the values to the array I wanted to make sure that it was working properly but i was getting garbage results. For example, for -12 i was only getting 3 results, one of which was above 100,000 :S