I need to help,I couldnt find wrong

  • Thread starter emre esirik(hacettepe computer science and enginee
  • Start date
E

emre esirik(hacettepe computer science and enginee

/////////////////////// DIVISION FUNCTION ////////////////////
void div ( int pol1[] , int pol1p[] , int pol2[] , int pol2p[])
{
int r=5,z,i,g,j,k,l,dividend[6],rising[6]={0};
for (i=0 ; i<6 ; i++)
dividend=pol1;
for(i=5 ; i >=0 ; i--)
{
r=5;
for(z=r ; z>=0 ; z--)
{

if(pol2[z]!=0)
{
*(po5 + (i-z))= dividend/pol2[z];
for(l=0; l<6; l++)
rising[l]=0;
for (j=z ; j>=0 ; j--) {
rising[i+j-z] = (*(po5 + i-z) * pol2[j]);
}
for(k=0; k<6 ; k++) {
dividend[k] = dividend[k] - rising[k];
}

}
r=z-1;
}
}
for (i=0 ; i<6 ; i++) {
printf("%dX^%d+",*(po5+i),i);
}



when first poly is like 3X^2 and second poly is like 1X its work
right, but it divides other poly wrongly, I couldnt find,helppp me
pleaseee
 
M

Mark Bluemel

emre esirik(hacettepe computer science and engineering) wrote:
[yet another request that we correct his coursework...]

Is C actually the most appropriate tool for what he's trying to do?

(I've been working with C for over 10 years and never done any
polynomial manipulation)

Might there be better alternatives?
 
E

emre esirik(hacettepe computer science and enginee

its my homework, I am studying at hacettepe university and we are
learning C language for a mounth and this is my 5.homework which I
have to do coding for poly :
„h Addition
„h Subtraction
„h Multiplication
„h Division
„h Derivation
„h Integration

-------The input will be in the following format:
ADD 3X^2+4X^1+7 2X^2+5
SUB 3X^2+4X+7 2X+5
DIV 3X^2+4X+7 X+3
MUL 3X^2+4X+7 X+3
DER 3X^4+4X^2+5X+7
INT 3X^2+4X+7

so I just trying to solve poly division, couldnt help me?
 
R

Richard Heathfield

Mark Bluemel said:
emre esirik(hacettepe computer science and engineering) wrote:
[yet another request that we correct his coursework...]

Is C actually the most appropriate tool for what he's trying to do?

It's an entirely appropriate tool, yes. Polynomial manipulation is just a
series of operations on array members. For example, I would do simple
integration something like this (and please understand that this is
off-the-cuff untested code):

struct term_
{
double factor;
double power;
};

typedef struct term_ term;

int integrate(term *t, size_t n)
{
int rc = 0; /* use this to report sillies eg /0 */
while(n-- > 0)
{
++t->power;
t->factor /= t->power;
++t;
}
return rc;
}

If the powers started getting bizarre (e.g. e^(i*pi)), then yes, okay,
that's a bit harder, but for simple polynomials of the form ax^n +
bx^(n-1) + ... + px^1 + qx^0 = y, I don't think that's such a difficult
thing to do in C, even at the student level.
 
E

emre esirik(hacettepe computer science and enginee

I am sorry but I couldnt make me clear, I did integrate, I just only
couldnt do division, its difficult for me
 
R

Richard Heathfield

emre esirik(hacettepe computer science and engineering) said:
I am sorry but I couldnt make me clear, I did integrate, I just only
couldnt do division, its difficult for me

No, you were very clear. My reply was directed at Mark, not at you. He
wanted to know whether C was the right tool for the job. I think he thinks
this is harder than it really is.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top