c语言错误怎么办?
用数组编的多项式乘法,但是不会合并同类项从同学那参考了合并的方法,但是有错误比较着急!!下面是程序#include#defineN100voidmultiply(inta...
用数组编的多项式乘法,但是不会合并同类项
从同学那参考了合并的方法,但是有错误
比较着急!!
下面是程序
#include
#define N 100
void multiply(int a[],int b[], int a,int b)
{
int i,j,s=a+b;
int c[N]={0};
for(i=0;i<=a;i++)
for(j=0;j<=b;j++)
c[i+j]+=a[i]*b[j];
printf("a(x)*b(x)=");
for(i=s;i>=1;i--)
printf("%dx^%d+",c[i],i);
printf("%d\n",c[0]);
}
void main()
{
int i,j,k=0;
int m=0,n=0;
int a[50],b[50],c[2500];
printf("Please input the highest exponencial of A\n");
scanf("%d",&m);
printf("Please input the coefficient of A\n");
for(i=0;i<m+1;i++)
scanf("%d",&a[i]);
printf("Please input the highest exponencial of B\n");
scanf("%d",&n);
printf("Please input the coefficient of B\n");
for(j=0;j<n+1;j++)
scanf("%d",&b[j]);
multiply(a[],b[],m,n);
}
这是错误
c(3) : error C2040: 'a' : 'int ' differs in levels of indirection from 'int *'
c(3) : error C2040: 'b' : 'int ' differs in levels of indirection from 'int *'
c(5) : error C2110: cannot add two pointers
c(7) : warning C4047: '<=' : 'int ' differs in levels of indirection from 'int *'
c(8) : warning C4047: '<=' : 'int ' differs in levels of indirection from 'int *'
c(30) : error C2059: syntax error : ']'
求大神指点啊,这个作业我都写了半个多月了,本人比较脑残,开始是用链表和结构体编的,但是实在编不出来,然后就编了这个,是把多项式的系数放到了数组里,可是又不会合并。。。 展开
从同学那参考了合并的方法,但是有错误
比较着急!!
下面是程序
#include
#define N 100
void multiply(int a[],int b[], int a,int b)
{
int i,j,s=a+b;
int c[N]={0};
for(i=0;i<=a;i++)
for(j=0;j<=b;j++)
c[i+j]+=a[i]*b[j];
printf("a(x)*b(x)=");
for(i=s;i>=1;i--)
printf("%dx^%d+",c[i],i);
printf("%d\n",c[0]);
}
void main()
{
int i,j,k=0;
int m=0,n=0;
int a[50],b[50],c[2500];
printf("Please input the highest exponencial of A\n");
scanf("%d",&m);
printf("Please input the coefficient of A\n");
for(i=0;i<m+1;i++)
scanf("%d",&a[i]);
printf("Please input the highest exponencial of B\n");
scanf("%d",&n);
printf("Please input the coefficient of B\n");
for(j=0;j<n+1;j++)
scanf("%d",&b[j]);
multiply(a[],b[],m,n);
}
这是错误
c(3) : error C2040: 'a' : 'int ' differs in levels of indirection from 'int *'
c(3) : error C2040: 'b' : 'int ' differs in levels of indirection from 'int *'
c(5) : error C2110: cannot add two pointers
c(7) : warning C4047: '<=' : 'int ' differs in levels of indirection from 'int *'
c(8) : warning C4047: '<=' : 'int ' differs in levels of indirection from 'int *'
c(30) : error C2059: syntax error : ']'
求大神指点啊,这个作业我都写了半个多月了,本人比较脑残,开始是用链表和结构体编的,但是实在编不出来,然后就编了这个,是把多项式的系数放到了数组里,可是又不会合并。。。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询