多项式相乘实现的c语言代码.txt
来自「c语言的一些常见的算法以及思考和改进的文章,写的很不错,花费了很大的精力从网络了」· 文本 代码 · 共 49 行
TXT
49 行
计算多项式乘积之常规算法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 + =
减小字号Ctrl + -
显示快捷键?