C언어 다항수의 곱셈 질문드립니다ㅠㅠ

조회수 3012회

'#include

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]);
}'

  • (•́ ✖ •̀)
    알 수 없는 사용자

1 답변

  • 답변은 아니고요.

    #include<stdio.h>
    #define MAX_DEGREE 10
    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]);  
    }
    

    마크다운 문법을 사용해주세요...

    • (•́ ✖ •̀)
      알 수 없는 사용자
    • 사이다네요. :-) 박기선 2016.4.7 21:13

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)