#include <stdio.h>
#include<stdlib.h>
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MAX_DEGREE 201
typedef struct polynomial{
int degree;
int coef[MAX_DEGREE];
} polynomial;
polynomial POLY_ADD(polynomial a, polynomial b) {
polynomial c;
int Apos = 0, Bpos = 0, Cpos = 0;
int Adegree = a.degree;
int Bdegree =b.degree;
c.degree = MAX(a.degree, b.degree);
for(int i=0;i<=c.degree;i++)
c.coef[i]=0;
while (Apos <= a.degree && Bpos <= b.degree) {
if (Adegree>Bdegree) {
c.coef[Cpos++] = a.coef[Apos++];
Adegree--;
}
else if (Adegree==Bdegree) {
c.coef[Cpos++] = a.coef[Apos++] + b.coef[Bpos++];
Adegree--;Bdegree--;
}
else {
c.coef[Cpos++] = b.coef[Bpos++];
Bdegree--;
}
}
return c;
}
polynomial POLY_SUB(polynomial a, polynomial b) {
polynomial c;
int Apos = 0, Bpos = 0, Cpos = 0;
c.degree = MAX(a.degree, b.degree);
int Adegree = a.degree;
int Bdegree =b.degree;
for(int i=0;i<=c.degree;i++)
c.coef[i]=0;
while (Apos <= a.degree && Bpos <= b.degree) {
if (Adegree > Bdegree) {
c.coef[Cpos++] = a.coef[Apos++];
Adegree--;
}
else if (Adegree == Bdegree) {
c.coef[Cpos++] = a.coef[Apos++] - b.coef[Bpos++];
Adegree--; Bdegree--;
}
else {
c.coef[Cpos++] = b.coef[Bpos++];
Bdegree--;
}
}
return c;
}
polynomial POLY_MUL(polynomial a, polynomial b) {
polynomial c;
int Cpos = 0;
c.degree = a.degree + b.degree;
for(int i=0;i<=c.degree;i++)
c.coef[i]=0;
int Adegree = a.degree;
int Bdegree =b.degree;
for (int Apos=0; Apos <= Adegree; Apos++)
{
for (int Bpos =0; Bpos <=Bdegree; Bpos++)
{
Cpos = c.degree -Apos- Bpos ;
c.coef[Cpos] +=( a.coef[Apos] * b.coef[Bpos]);
}
}
return c;
}
void poly_print(polynomial c) {
for (int i = 0; i<=c.degree; i++) {
printf("%d ", c.coef[i]);
}
printf("\n");
}
int main() {
polynomial p1, p2, p3;
scanf("%d", &p1.degree);
for (int i = 0; i <= p1.degree; i++)
scanf("%d", &p1.coef[i]);
scanf("%d", &p2.degree);
for (int i = 0; i <= p2.degree; i++)
scanf("%d", &p2.coef[i]);
p3 = POLY_ADD(p1, p2);
poly_print(p3);
p3 = POLY_SUB(p1, p2);
poly_print(p3);
p3 = POLY_MUL(p1, p2);
for(int i = p3.degree; i>=0; i--){
printf("%d ", p3.coef[i]);
}
return 0;
}
값은 출력 예시대로 나오는데용 ㅜㅜ
왜 컴파일에러인 건가요ㅜㅜ