#include<stdio.h>
#define MAX_DEGREE 101
typedef struct{
int degree;
float coef[MAX_DEGREE];
}polynomial;
polynomial poly_product(polynomial A,polynomial B)
{
int i,j;
polynomial C,Tmp;
int degree_a=A.degree;
int degree_b=B.degree;
C.degree=A.degree+B.degree;
for(i = 0; i < MAX_DEGREE; i++)
{
C.coef[i] = 0;
}
for(i=0;i<=degree_a;i++){
for(j=0; j<=degree_b;j++){
C.coef[i+j]+=A.coef[i]*B.coef[j];
}
}
return C;
}
void main(void)
{
polynomial a = { 5, {10, 0, 0, 0, 6, 3} };
polynomial b = { 4, {1, 0, 5, 0, 7} };
polynomial c;
c = poly_product(a,b);
int i;
printf("차수 : %d차식\n",c.degree);
for(i=c.degree;i>0;i--)
{
printf("%d차 계수 : %.2lf\n",i,c.coef[i]);
}
printf("상수 : %.2lf\n",c.coef[0]);
}
다항식의 덧셈을 곱셈으로 바꾼건데, 오름차순으로 안나오고 내림차순으로 나오네요 어떻게 바꾸어야 할까요? ㅠㅠ
제발 알려주세요
I >0 을 I <0 으로 바꾸몀안됨?
안된다 ㅠㅠ