행열 연산자 에 관한 질문입니다! 수정부탁드려요 ㅠ
피리
자료구조문제행열 연산자 문제인데 제가 보고 코드는 짜봣는데
컴파일이 됫다가 바로꺼저버리네요,,ㅠ
이거 print에서 i=max_size-1로 시작해야 되고 poly[i]는 %f로 뽑아야 되고
맨위에 배열 4개 선언한거 다 지워야되는듯 이렇다는데 뭔소린지 모르겟어서요 ㅠㅠ
도와주세요~1. implement the following operation for polynomials with arrays. submit the source code with inline comments and the execution result (screen shot).?xml:namespace prefix = o ns = urn:schemas-microsoft-com:office:office /?xml:namespace prefix = o /?xml:namespace prefix = o /?xml:namespace prefix = o /
#define max_size 100
enum {false, true} bool ;
void add( float* poly3, float *poly1, float *poly2 )
addition of two polynomials (poly3 = poly1 + poly2)
void mult( float *poly3, float *poly1, float *poly2 )
multiplication of two polynomials, (poly3 = poly1 * poly2)
if the exponent of some terms in poly3 exceeds the maximum exponent, you may discard those terms
bool attach( float * poly, float coef, int expon )
adding the term of coef xexpon into poly
return true if attach is successful
return false if expon is out of range or the term with expon already exists in poly
bool remove( float *poly, int expon )
removingremoving the term with expon from poly
return true if successful
return false if the term with expon does not exist
float coef( float *poly, int expon )
obtaining the coefficient of xexpon
int lead_exp( float *poly )
obtaining the exponent of the leading (the highest order) term of poly
void print(float* poly)
printing poly in the following format:
3x5+2x3+1 - 3*x^5+2*x^3+1
(이것이 문제고)#include stdio.h
#define max_size 100
float poly[max_size];
float poly1[max_size];
float poly2[max_size];
float poly3[max_size];
void add( float* poly3, float *poly1, float *poly2 )
{
int i;
for (i=0; imax_size; i++)
poly3[i]=poly1[i]+poly2[i];
}
void mult( float *poly3, float *poly1, float *poly2 )
{
int i;
int j;
int k;
for (i=0; imax_size; i++)
{
for (j=0; jmax_size;j++)
{
k=i+j;
if (kmax_size)
poly3[k]=poly1[i]*poly2[j];
}
}
}
bool attach( float * poly, float coef, int expon )
{
if(exponmax_size)
return false;
else if (poly[expon] == 0)
{
poly[expon] = coef;
return true;
}
else if (poly[expon] != 0)
return false;
}
bool remove( float *poly, int expon )
{
if (poly[expon] == 0)
return false;
else
{
poly[expon]=0;
return true;
}
}
float coef( float *poly, int expon )
{
return poly[expon];
}
int lead_exp( float *poly )
{
int i=max_size-1;
while(0 i){
if (poly[i]!=0)
break;
else
i--;
}
return i;
}
void print(float* poly)
{
int i=max_size;
while(i=0)
{
if (poly[i]!=0)
{
printf(%dx^%d, poly[i] ,i);
if(i!=0)
{
printf( +);
}
}
i--;
}
}
int main() {
float poly1[max_size]={1,2,3,4};
float poly2[max_size]={4,3,2,1};
print(poly1);
return 0;
}
(제가 짠 코드)