已知字符数组a10和b10中元素的值递增有序封装函数并用指针实现将两个数组中元素按照递增顺序输出。
#include <stdio.h>
void printIncreasingOrder(int *a, int *b, int size) {
int i = 0, j = 0, k = 0;
int c[20];
while (i < size && j < size) {
if (a[i] < b[j]) {
c[k++] = a[i++];
} else {
c[k++] = b[j++];
}
}
while (i < size) {
c[k++] = a[i++];
}
while (j < size) {
c[k++] = b[j++];
}
printf("The elements in increasing order: ");
for (int m = 0; m < 2 * size; m++) {
printf("%d ", c[m]);
}
printf("\n");
}
int main() {
int a[10] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19};
int b[10] = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20};
printIncreasingOrder(a, b, 10);
return 0;
}
``
原文地址: https://www.cveoy.top/t/topic/eXME 著作权归作者所有。请勿转载和采集!