ugent.. pls help with my program

cire09's Avatar, Join Date: Feb 2010
Light Poster
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 shabbir; 27Feb2010 at 18:23.. Reason: Code blocks
0
cire09's Avatar, Join Date: Feb 2010
Light Poster
uhm.. can u give me a source code of this program... pls
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by cire09 View Post
uhm.. can u give me a source code of this program... pls
This is your program and you have posted the source code only.
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
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.