I am trying to compare 2 arrays ( a
and b
respectively) and the value of a
that is repeated in b
that forms another vector.
I have put it this way: when I want to compare the values entered in b
with a
I get an error and I can not understand how to solve it.
int[] a = new int[2];
int[] b = new int[2];
int[] c = new int[2];
int n = 0, m = 0, i, k, l=0;
for (i = 0; i < a.Length; i++)
{
Console.WriteLine("Ingrese numero vector A");
a[i] = Convert.ToInt32(Console.ReadLine());
}
for (k= 0; k < b.Length; k++)
{
Console.WriteLine("Ingrese numero vector B");
b[k] = Convert.ToInt32(Console.ReadLine());
//Comparo el valor de b que estoy guardando con la posicion de a. si es correcto se guarda en el vector c
if (b[k] == a[i])
{
b[k] = c[l];
Console.WriteLine("C: " + c[l]);
}
}