practica 11
TRANSCRIPT
UNIVERSIDAD NACIONAL DE CHIMBORAZO
FACULTAD DE CIENCIAS DE LA EDUCACION HUMANAS Y
TECNOLOGIAS
PRACTICA 11
EJERCICIO 1
1.- se introduce atreves de teclado dos vectores A de n elementos y B de m elementos.
Fusionar los dos vectores en un tercer vector e imprimir. (si existe elementos repitos solo debe mantenerse una sola vez el elemento)
//Aguagallo Doris //
package cypractica11;
import java.util.Scanner;
class fufiona_n_elementos
{
public static void main(String arg [])
{
Scanner datos=new Scanner (System.in);
int [] a=new int [5000];
int [] b=new int [5000];
int n,m,y,j,i,x=0;
{ System.out.println("======FUS ION DE DOS VECTORES===== \n");
System.out.println("******INGRES E EL TAMAÑO DEL VECTOR A*****\n");
n=datos.nextInt();;
for(i=0;i<n;i++)
{ System.out.println("=====INGRES E EL ELEMENTO=====\n");
a[i]=datos.nextInt();
} System.out.println("****INGRES E EL TAMAÑO DEL VECTOR B*** \n");
m=datos.nextInt();;
for(j=0;j<m;j++)
{ System.out.println("=====INGRES E EL ELEMENTO=====\n");
b[j]=datos.nextInt();
}
y=n+m;
i=0;
j=0;
int [] c=new int [y];
for (i = 0; i < n; i++)
{
c[i] = a[i];
}
for (i = n; i < y; i++)
{
c[i] = b[i-n];
}
for (i = 0; i < y - 1; i++)
{
for (j = i + 1; j < y; j++)
{
if (c[i] == c[j])
{
c[j] = -4000;
}
}
}
for (i = 0; i < y; i++)
{
if (c[i] != -4000)
{
x++;
}
}
int[] d = new int[x];
j = 0;
for (i = 0; i < y; i++)
{
if (c[i] != -4000)
{
d[j] = c[i];
j++;
}
} System.out.println("\n*****=====LA FUSION DE DOS VECTORES ES====******\n");
for (i = 0; i < x; i++)
{ System.out.println(" \n"+ d[i]);
} System.out.println("\n");
}
}
}
SOLUCION