0
I need to make a program that reads the values of two vectors R
and S
, and store its values in a third vector called V
. The detail is that it cannot contain any repeated element in the vector V
.
I managed to get the program to show the vector V
whole resulting from the union of R
and S
, but I still haven’t been able to figure out a way not to put repeat elements in V
.
Follow the algorithm I made:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Exercício6Testes
{
class Program
{
static void Main(string[] args)
{
int[] R = new int[10];
int[] S = new int[10];
int[] V = new int[20];
Console.WriteLine("Este programa lê dois vetores e mostra a união dos dois sem valores repetidos");
Console.WriteLine("Digite os 10 valores do vetor R: ");
Console.WriteLine("\n");
for (int i = 0; i < 10; i++)
{
Console.Write("Digite o valor de R{0}: ", i + 1); //LÊ O 1° VETOR
R[i] = int.Parse(Console.ReadLine());
}
Console.Clear();
Console.WriteLine("Agora digite os valores do vetor S: ");
for (int j = 0; j < 10; j++)
{
Console.Write("Digite o valor de S{0}: ", j + 1); //LÊ O SEGUNDO VETOR
S[j] = int.Parse(Console.ReadLine());
}
for (int k = 0; k < 10; k++)
{
V[k] = R[k]; //AQUI COLOCA TODOS OS VALORES DO VETOR R NAS
//10 PRIMEIRAS POSIÇÕES DO VETOR V
}
int kw = 10;
for (int L = 0; L < 10; L++)
{
V[kw] = S[L]; //AQUI COLOCA TODOS OS VALORES DO VETOR S NA
kw++; //SEGUNDA METADO DO VETOR V
}
Console.Clear();
Console.WriteLine("União dos dois vetores: ");
for(int mostra = 0; mostra < 20; mostra++)
{
Console.Write(V[mostra] + "\t"); //AQUI MOSTRA A UNIÃO DOS DOIS VETORES R e S DENTRO
//DO VETOR V.
//MOSTRA TUDO, ATÉ OS REPETIDOS!+......
}
Console.ReadKey();
}
}
}
Is this for educational purposes? Is it a job? I wonder why in C# there are much simpler ways to do what you want.
– João Martins
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site
– Maniero