Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   ugent.. pls help with my program (http://www.go4expert.com/forums/ugent-pls-help-program-t21145/)

 cire09 27Feb2010 17:42

ugent.. pls help with my program

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); }```

 cire09 28Feb2010 19:38

Re: ugent.. pls help with my program

uhm.. can u give me a source code of this program... pls

 shabbir 28Feb2010 20:10

Re: ugent.. pls help with my program

Quote:
 Originally Posted by cire09 (Post 64896) uhm.. can u give me a source code of this program... pls
This is your program and you have posted the source code only.

 xpi0t0s 28Feb2010 23:07

Re: ugent.. pls help with my program

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.

 All times are GMT +5.5. The time now is 20:04.