Untitled
unknown
c_cpp
a year ago
689 B
4
Indexable
Never
#include<stdio.h> #include<stdlib.h> int* array(int n) { return (int*)malloc(sizeof(int) * n); } int main() { int m,n; // nhap mang 1 scanf("%d",&m); int* a = array(m); for(int i = 0 ;i < m ;i ++) scanf("%d",&a[i]); // nhap mang 2 scanf("%d",&n); int* b = array(n); for(int i = 0;i < n;i ++) scanf("%d",&b[i]); // mang ket qua int* res = array(m + n); // tao 2 con tro i va j int i = 0, j = 0; while(i < m && j < n) if(a[i] < b[j]) res[i+j] = a[i++]; else res[i+j] = b[j++]; while(i < m) res[i+j] = a[i++]; while(j < n) res[i+j] = b[j++]; // in ket qua for(int z = 0 ;z < i +j ; z++) printf("%d ",res[z]); }