错误:数组下标的类型"int[int]"无效|



代码返回错误:数组下标|无效类型'int[int]',其他一切似乎运行正常。我该怎么办呢?(10号线,22、23)

#include <iostream>
using namespace std;
int n, x[50], y[50], z[50];
void citire(int &n, int v)
{
int i;
cin >> n;
for (int i = 1; i <= n; i++)
{
cout << "v[" << i << "]=";
cin >> v[i];
}
}
void afisare(int n, int v[])
{
int i;
for (i = 1; i <= n; i++)
cout << v[i] << " " << endl;
}
void s(unsigned n, int x[], int y[], int z[])
{
int i;
for (i = 1; i <= n; i++)
z[i] = abs(x[i] - y[i]);
}
int main()
{
cout << "n=";
cin >> n;
cout << "x[]:" << endl;
citire(n, x);
cout << "y[]:" << endl;
citire(n, y);
cout << "Elementele primului vector" << endl;
afisare(n, x);
cout << "Elementele celui de-al doilea vector:" << endl;
afisare(n, y);
s(n, x, y, z);
cout << "z[]:" << endl;
return 0;
}

您使用v作为数组,但它不是数组,它是int。您可能想使用int* v

void citire(int &n, int* v) {
// ...
cin>>v[i];
}

相关内容

  • 没有找到相关文章

最新更新