# ugent.. pls help with my program

Discussion in 'C' started by cire09, Feb 27, 2010.

1. ### cire09New Member

Joined:
Feb 27, 2010
Messages:
5
0
Trophy Points:
0
pls help with my school project... its a program that get the factors of an algebriac expression... my problem is the output... when i input a = 1, b = 5, c =6 the output is correct but when i input a = 5, b = 26, c = 24 the output is (4x+6)(1x+5) the correct output must be (5x+6)(1x+4)..

here's my wrong work.. pls help me correct it.. i've been working it for 2 weeks and i still can't make it right..

Code:
```#include<stdio.h>
void factor(int a,int b,int c);
void factor1(int a,int b,int c,int d);

main()
{
int a,b,c;
clrscr();
printf("enter the value of a,b,c for the equation ax^2 + bx + c:\n");
printf("a = ");
scanf("%d",&a);
printf("b = ");
scanf("%d",&b);
printf("c = ");
scanf("%d",&c);
printf("the equation now is %dx^2 + %dx + %d",a,b,c);
factor(a,b,c);
getch();
}

void factor(int a,int b, int c)
{
float sum;
int i=0,start,fctr1;
start = a * c;
do
{
i++;
if(start%i==0){
fctr1=start/i;
sum=fctr1+i;}
}while(sum>b);
if(sum==b){
printf("\nThe equation is factorable and\nthe factors are: ");
factor1(fctr1,a,c,i);}
else
printf("\nThe equation is not factorable!!");
}

void factor1(int a,int b,int c,int d)
{
float w,y,l,i,n,e;
int x=0,z=0;
do
{
do
{
x++;
w=a/x;
n=w*x;
}while(n<a);
do
{
z++;
y=d/z;
e=y*z;
}while(e<d);
l=x*z;
i=y*w;
}while((l<c)&&(i>b));
if((w==y)&&(z==x))
printf("(%.0fx+%i)^2",w,z);
else
printf("(%.0fx+%i)(%.0fx+%i)",w,z,y,x);
}```

Last edited by a moderator: Feb 27, 2010
2. ### cire09New Member

Joined:
Feb 27, 2010
Messages:
5
0
Trophy Points:
0
uhm.. can u give me a source code of this program... pls

Joined:
Jul 12, 2004
Messages:
15,292
365
Trophy Points:
83
This is your program and you have posted the source code only.

4. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,012
203
Trophy Points:
0
Occupation:
Senior Support Engineer
Location:
England
Please explain the algorithm, and what each variable is used for. Single letter variable names tell us nothing about what they are for.

Have you tried to find out where the values in the variables start going wrong? If you print the relevant variables after each line, then you will be able to follow through the program working out what the values should be, and checking after each line what the values are. Then you will be able to spot the differences and then you can work out why it is going wrong.