// program to multiply two polynomials #include void multiply(double f[], double g[], double h[], int m, int n, int *k); int main() { double f[10],g[10],h[20]; int m,n,k,i,j; printf("enter the degrees of two polynomials f and g values should be <=9 \n"); scanf("%d %d",&m,&n); // enter the coefficients of polynomial f and store such that f[0] contains x^0 coefficient f[1] contains x^1 coefficient and so on.... printf("enter the coefficients of polynomial f\n"); for(i=0;i<=m;i++) scanf("%lf",&f[i]); // enter the coefficients of polynomial g and store such that g[0] contains x^0 coefficient g[1] contains x^1 coefficient and so on.... printf("enter the coefficients of polynomial g\n"); for(i=0;i<=n;i++) scanf("%lf",&g[i]); multiply(f,g,h,m,n,&k); printf("result of multiplying polynoimials\n"); for(i=m;i>0;i--) printf("%lf * x^%d + ",f[i],i); printf("%lf * x^%d ",f[i],i); printf("\n and\n"); for(i=n;i>0;i--) printf("%lf * x^%d + ",g[i],i); printf("%lf * x^%d ",g[i],i); printf("\n is\n"); for(i=k;i>0;i--) printf("%lf * x^%d + ",h[i],i); printf("%lf * x^%d ",g[i],i); //for(i=0;i<=k;i++) //printf("%lf \t",h[i]); return 0; } // function to multiply void multiply(double f[], double g[], double h[], int m, int n, int *k) { int i,j; //order of resulting polynomial *k=m+n; for(i=0;i<=*k;i++) h[i]=0.0; for(i=0;i<=n;i++) { for(j=0;j<=m;j++) { h[i+j]+=f[j]*g[i]; } } }