the code returns error: invalid types 'int[int]' for array subscript| and everything else seems to run fine. What can I do about it ? (line 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;
}
50fornat program start is going to invoke undefined behavior.std::vectoror any other proper container, all your loops will cause undefined behavior