Untitled
Anonymous
plain_text
04/24/2026 12:44 AM
1.7 KB
11
Indexable
#include <stdio.h>
void fusionar(int X[], int tamX, int Y[], int tamY, int resultado[], int tamR) {
int i = 0, j = 0, k = 0;
int temp[tamX + tamY];
int t = 0;
for (int idx = 0; idx < tamX; idx++) {
if (X[idx] != 0) {
temp[t] = X[idx];
t++;
}
}
for (int idx = 0; idx < tamY; idx++) {
temp[t] = Y[idx];
t++;
}
for (int a = 0; a < t - 1; a++) {
for (int b = a + 1; b < t; b++) {
if (temp[a] > temp[b]) {
int aux = temp[a];
temp[a] = temp[b];
temp[b] = aux;
}
}
}
for (int idx = 0; idx < tamR; idx++) {
resultado[idx] = temp[idx];
}
}
void imprimirArreglo(int arr[], int n) {
printf("{");
for (int i = 0; i < n; i++) {
printf("%d", arr[i]);
if (i < n - 1) printf(", ");
}
printf("}\n");
}
int main() {
int X[] = {0, 2, 0, 3, 0, 5, 6, 0, 0};
int Y[] = {1, 8, 9, 10, 15};
int tamX = 9;
int tamY = 5;
int tamR = tamX;
int resultado[9];
fusionar(X, tamX, Y, tamY, resultado, tamR);
printf("X[] = ");
imprimirArreglo(resultado, tamR);
return 0;
}Editor is loading...
Leave a Comment