C 语言,将两个数组合并到另外一个数组中,并且合并之后的数组是有序的。
来源:互联网 发布:node.js express 编辑:程序博客网 时间:2024/05/16 19:09
<span style="font-size:18px;"> int a[10] = {0}; int b[10] = {0}; int c[20] = {0}; printf("a数组为:"); for (int i = 0; i < 10; i++) { a[i] = arc4random()%(40 - 20 + 1) + 1;//为数组生成随机元素 printf("%d ", a[i]); } printf("\nb数组为:"); for (int j = 0; j < 10; j++) { b[j] = arc4random()%(40 - 20 + 1) + 1;//为数组生成随机元素 printf("%d ", b[j]); } int i= 0 , j = 0 ,k = 0; while (i < 10) { c[k++] = a[i++];//将a数组导入到c数组中 } while (j < 10) { c[k++] = b[j++];//将b数组导入到c数组中 } printf("\nc数组为:"); for (int i = 0; i < 20; i++) { printf("%d ", c[i]);//输出c数组的元素 } //使用冒泡排序,将c数组从小到大排序 for (int i = 0; i < 20 -1; i++) { for (int j = 0; j < 20 - 1 - i; j++) { if (c[j] > c[j + 1]) { int temp = c[j]; c[j] = c[j + 1]; c[j + 1] = temp; } } } printf("\n合并排完序后的c数组为:"); //打印输出c数组 for (int i = 0; i < 20; i++) { printf("%d ", c[i]); }</span>
<span style="font-size:18px;">随机输出结果为:</span>
<span style="font-size:18px;"></span><pre name="code" class="cpp">a数组为:10 10 8 19 18 21 11 19 2 16 b数组为:20 17 5 12 19 4 7 17 19 4 c数组为:10 10 8 19 18 21 11 19 2 16 20 17 5 12 19 4 7 17 19 4 合并排完序后的c数组为:2 4 4 5 7 8 10 10 11 12 16 17 17 18 19 19 19 19 20 21
0 0
- C 语言,将两个数组合并到另外一个数组中,并且合并之后的数组是有序的。
- 4.将两个排好序的数组,合并到另外一个数组中,并且合并之后的数组也是有序的。
- 将两个排好序的数组,合并到另外一个数组中,并且合并之后的数组也是有序的。
- 将两个排好序的数组,合并到另外一个数组中,并且合并之后的数组也是有序的。
- 将两个排好序的数组,合并到另外一个数组中,并且合并之后的数组也是有序的。
- 将两个排好序的数组,合并到另外一个数组中,并且合并之后的数组也是有序的。
- 将两个排好序的数组,合并到另外一个数组中,并且合并之后的数组也是有序的。
- C语言实现:合并两个有序的数组,合并后的数组依然有序
- 给定两个有序数组,找出合并之后的数组中位数
- 合并两个有序数组为一个新的有序数组
- 合并两个有序的数组
- 合并两个有序的数组
- 将两个有序的数组合并成一个有序的数组
- java将两个有序数组合并成一个有序数组
- 两个已经排好序的数组合并到一个数组中
- 合并两个有序数组,合并之后也是有序数组
- 寻找两个有序数组合并之后的中位数
- 两个有序单链表的合并&两个有序数组的合并
- makefile中的一点知识
- .Net中DataGridview数据如何导出到excel表
- 醉月湖畔,为谁染红妆
- 还是A+B
- 重天乾 4-3
- C 语言,将两个数组合并到另外一个数组中,并且合并之后的数组是有序的。
- error: Error retrieving parent for item: No resource found that matches the given name 'android:Them
- ASP.NET MVC 视图(二)
- OC内存管理
- POJ 2366 Sacrament of the sum(二分查找)
- 果园里的快乐时光
- 数据库存储过程实现高效分页
- PhoneGap 之环境搭建
- 重天乾 4-2