如何删除此错误? [英] How to remove this error?
问题描述
#include<stdio.h>
int dot_product(int n,int *aa,int *bb)
{
int i,j,sum=0,temp;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(aa[i]>aa[j])
{
temp=aa[i];
aa[i]=aa[j];
aa[j]=temp;
}
}
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(bb[i]<bb[j])
{
temp=bb[i];
bb[i]=bb[j];
bb[j]=temp;
}
}
}
for(i=0;i<n;i++)
sum+=aa[i]*bb[i];
return sum;
}
int main()
{
int n,s,i,j;
scanf("%d",&n);
int a[n],b[n];
for(i=0;i<n;scanf("%d",a[i++]));
for(i=0;i<n;scanf("%d",b[i++]));
s=dot_product(int n,int a[n],int b[n]);
printf("%d",s);
return 0;
}
我的尝试:
错误:对'dot_product'函数的争论太少
What I have tried:
error:too few argiements to function 'dot_product'
推荐答案
查看错误消息:
Look at the error message:
too few argiements to function 'dot_product'
如果你复制'n'pasted错误信息,那就是:
If you had copy'n'pasted the error message, it would have been:
Too few arguments to function 'dot_product'
这让我们的生活变得更轻松,所以试着记住以后 - 有了更复杂的错误信息,它需要精确并复制' n'paste是确保这一点的最好方法。
但是信息非常清楚:你已经定义了一个名为 dot_product $的函数c $ c>有三个参数:
That makes our lives easier, so try to remember that in future - with more complex error messages, it needs to be exact and copy'n'paste is the best way to ensure that.
But the message is pretty clear: you have defined a function called dot_product
which takes three parameters:
int dot_product(int n,int *aa,int *bb)
但是当你调用它时,你指定的数据类型会混淆系统:
But when you call it, you are specifying the datatypes, which confuses the system:
s=dot_product(int n,int a[n],int b[n]);
试试这个s:
Try this:
s=dot_product(n, &(a[n]), &(b[n]));
将元素的地址传递给函数,虽然我认为你要做的是:
Which passes the addresses of the elements to the function, though I think what you are trying to do is this:
s=dot_product(n, a, b);
将指针传递给每个数组的第一个元素。
which will pass the pointer to the first element of each array.
这篇关于如何删除此错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!