Upgraded from Brain to Processor
My current math homework is factoring out trinomials, which can take a long time with a mere human brain. So my mom and I wrote a program to do this. It’s written in C and Objective-C (with the Foundation framework), but it shouldn’t be hard to port it to another language, if you’re not a UNIX user.
Here it is:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int num1, num2, num3, a, b, c, d;
NSMutableArray * num1Factors = [[NSMutableArray alloc] init];
NSMutableArray * num3Factors = [[NSMutableArray alloc] init];
printf("Enter the coefficient for x-squared: ");
scanf("%d", &num1);
printf("Enter the coefficient for x: ");
scanf("%d", &num2);
printf("Enter the constant: ");
scanf("%d", &num3);
int i;
int plusNum1;
if (num1 0)
{
c = -c;
d = -d;
}
// try it out, and if it doesn't work, start over with the next pair of factors
if ((c*b)+(a*d) == num2)
{
printf("(%dx+%d)(%dx+%d)", a, c, b, d);
flag = NO;
}
j1 += 2;
j2 += 2;
}
i1 += 2;
i2 += 2;
}
[num1Factors release];
[num3Factors release];
[pool release];
return 0;
}