您的位置:首页 > 其它

合并两个有序数组

2015-11-24 18:21 363 查看
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>

int _tmain(int argc, _TCHAR* argv[])
{
int a[5] = {0,2,5,7,8};
int b[5] = {1,3,4,6,9};
int c[10],i,x,y,z;

x=0;y=0;z=0;
while(x<5&&y<5)
{
if(a[x]<b[y])
{
c[z]=a[x];
x++;
}
else{
c[z]=b[y];
y++;
}
z++;
}
while(x<5)
{
c[z]=a[x];
x++;
z++;
}
while(y<5)
{
c[z]=b[y];
y++;
z++;
}
for(i=0;i<10;i++)
{
printf("%5d",c[i]);}

system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: