#include
using namespace std;
int main()
{
int i, j, m, n,p[m],q[n],s[m+n]; //数组个数要搞清!易错点在这!
cout<<"输入第一行的个数:"; cin>>m;
cout<<"输入系数: ";
for (i = m-1; i >=0; i--) //为第一列系数
{
cin>>p[i];
}
cout<<"P(X)=";
for (i=m-1; i>=0; i--)
{
if(i==0) {cout<<p[i];break;}
cout<<p[i]<<"×X^"<<i<<"+";
}
cout<<"\n\n";
cout<<"输入第二行的个数:";cin>>n;
cout<<"输入系数: ";
for (i = n-1; i >=0; i--) //第二列系数
{
cin>>q[i];
}
cout<<"Q(X)=";
for (i=n-1; i>=0; i--)
{
if(i==0) {cout<<q[i];break;}
cout<<q[i]<<"×X^"<<i<<"+";
}
cout<<"\n\n";
for (i = m + n-2; i >=0; i--) //都是零
{s[i] = 0;}
for (i = m-1; i>=0; i--)
{
for (j = n-1; j >=0; j--)
{
s[i + j] += p[i] * q[j];
}
}
cout<<"它们乘积多项式:S(X)=";
for (i=m+n-2; i>=0; i--) //输出所搞的
{
if(i==0){cout<<s[i];break;}
cout<<s[i]<<"×X^"<<i<<"+";
}
}