왜 컴파일에러가 뜨는 건가요ㅠㅠ

shinsoomin Reply 7 years 28 weeks ago
#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; } 값은 출력 예시대로 나오는데용 ㅜㅜ 왜 컴파일에러인 건가요ㅜㅜ
withcs1 Reply 7 years 28 weeks ago
problem에 제시된 sample code가 제출하신 코드에 같이 들어가게됩니다 이때문제 제출된 코드를 보니 polynomial 정의도 중복되고 main함수도 두개로 나오고있었네요 이를 고려하고 짜시면 될듯 합니다