Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board
Go4Expert
Go4Expert RSS Feed

Go Back   Programming and SEO Forum >  Go4Expert > Queries and Discussion > Programming > C-C++

Reply  Copy HTML to Clipboard  Copy BBCode to Clipboard  | More
 
Bookmarks Thread Tools Search this Thread Display Modes
Old 02-27-2010, 04:42 PM   #1
Newbie Member
 
Join Date: Feb 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
cire09 is on a distinguished road

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

Last edited by shabbir; 02-27-2010 at 05:23 PM.. Reason: Code blocks
cire09 is offline   Reply With Quote
Old 02-28-2010, 06:38 PM   #2
Newbie Member
 
Join Date: Feb 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
cire09 is on a distinguished road

Re: ugent.. pls help with my program


uhm.. can u give me a source code of this program... pls
cire09 is offline   Reply With Quote
Old 02-28-2010, 07:10 PM   #3
Go4Expert Founder
 
shabbir's Avatar
 
Join Date: Jul 2004
Location: On Earth
Posts: 12,750
Thanks: 131
Thanked 294 Times in 228 Posts
Rep Power: 10
shabbir has much to be proud ofshabbir has much to be proud ofshabbir has much to be proud ofshabbir has much to be proud ofshabbir has much to be proud ofshabbir has much to be proud ofshabbir has much to be proud ofshabbir has much to be proud of
Send a message via Yahoo to shabbir

Re: ugent.. pls help with my program


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.
shabbir is offline   Reply With Quote
Old 02-28-2010, 10:07 PM   #4
Mentor
 
Join Date: Aug 2004
Posts: 2,136
Thanks: 3
Thanked 77 Times in 67 Posts
Rep Power: 13
xpi0t0s is just really nicexpi0t0s is just really nicexpi0t0s is just really nicexpi0t0s is just really nicexpi0t0s is just really nice

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.
xpi0t0s is offline   Reply With Quote
Reply  Copy HTML to Clipboard  Copy BBCode to Clipboard  | More


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Bookmarks

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

 

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