📄 多项式相乘实现的c语言代码.txt
字号:
计算多项式乘积之常规算法C语言实现[原创]
设有多项式相乘(9x3+9x2+9x+9)*(9x2+9x+9),计算过程如下:
(9x3+9x2+9x+9)*(9x2+9x+9)=81x5+81x4 +81x3
+81x4 +81x3 +81x2
+81x3 +81x2 +81x
+81x2 +81x +81
=81x5+162x4+243x3+243x2 +162x +81
模拟该过程的C语言代码为:
#i nclude <conio.h>
#i nclude <stdlib.h>
void product(int x[],int y[],int z[],int n,int m)
{
int i,j;
for(i=0;i<n+m-1;i++)
z[i]=0;
for(i=0;i<n;i++)
for(j=0;j<m;j++)
z[i+j]=z[i+j]+x[i]*y[j];
}
void output(int array[],int n)
{
int i,j;
j=n;
printf("\n");
for(i=0;i<n;i++)
printf("%dx^%d+",array[i],j--);
printf("%d\n",array[i]);
}
void main()
{
int x[4]={9,9,9,9},y[3]={9,9,9},z[6];
int i;
product(x,y,z,4,3);
clrscr();
printf("\nThe first poly is:\n");
output(x,3);
printf("\nThe second poly is:\n");
output(y,2);
printf("\nThe result poly is:\n");
output(z,5);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -