完成fun函数,将一个升序数组a和一个降序数组b中的所有元素按照降序存入到数组c中
#include<stdio.h>#defineN5#defineM8voidfun(inta[],intb[],intc[]){/**//**/}voidmain(){...
#include <stdio.h>
#define N 5
#define M 8
void fun(int a[],int b[],int c[])
{
/**/
/**/
}
void main()
{
int arra[N]={5,10,15,27,46},arrb[M]={50,45,42,29,15,8,5,2};
int arrc[N+M],k;
fun(arra,arrb,arrc);
printf("array arra is:");
for(k=0;k<N;k++)
printf("%d ",arra[k]);
printf("\narray arrb is:");
for(k=0;k<M;k++)
printf("%d ",arrb[k]);
printf("\nresult arrc is:");
for(k=0;k<N+M;k++)
printf("%d ",arrc[k]);
getch();
} 展开
#define N 5
#define M 8
void fun(int a[],int b[],int c[])
{
/**/
/**/
}
void main()
{
int arra[N]={5,10,15,27,46},arrb[M]={50,45,42,29,15,8,5,2};
int arrc[N+M],k;
fun(arra,arrb,arrc);
printf("array arra is:");
for(k=0;k<N;k++)
printf("%d ",arra[k]);
printf("\narray arrb is:");
for(k=0;k<M;k++)
printf("%d ",arrb[k]);
printf("\nresult arrc is:");
for(k=0;k<N+M;k++)
printf("%d ",arrc[k]);
getch();
} 展开
3个回答
展开全部
#include "stdafx.h"
#define N 5
#define M 8
int* fun(int a[],int b[],int c[])
{
int i = N + M;
int j = 0;
int k = 0;
int m = 0;
for (j=0;j<i;j++) //把a , b的值 放到 c中
{
if (j<N)
{
c[j] = a[j];
continue;
}
c[j] = b[k];
k++;
}
k = N+M;
while(k) //给c 降序
{
for (j=0;j<i;j++)
{
if (j+1>i)
{
break;
}
if (c[j]<c[j+1])
{
m = c[j];
c[j] = c[j+1];
c[j+1] = m;
}
}
k--;
}
return c;
}
int _tmain(int argc, _TCHAR* argv[])
{
int arra[N]={5,10,15,27,46},arrb[M]={50,45,42,29,15,8,5,2};
int arrc[N+M];
fun(arra,arrb,arrc);
int i = 0;
for (i=0;i<N+M;i++) //打印
{
printf("%d ",arrc[i]);
}
while(1)
{
}
return 0;
}
#define N 5
#define M 8
int* fun(int a[],int b[],int c[])
{
int i = N + M;
int j = 0;
int k = 0;
int m = 0;
for (j=0;j<i;j++) //把a , b的值 放到 c中
{
if (j<N)
{
c[j] = a[j];
continue;
}
c[j] = b[k];
k++;
}
k = N+M;
while(k) //给c 降序
{
for (j=0;j<i;j++)
{
if (j+1>i)
{
break;
}
if (c[j]<c[j+1])
{
m = c[j];
c[j] = c[j+1];
c[j+1] = m;
}
}
k--;
}
return c;
}
int _tmain(int argc, _TCHAR* argv[])
{
int arra[N]={5,10,15,27,46},arrb[M]={50,45,42,29,15,8,5,2};
int arrc[N+M];
fun(arra,arrb,arrc);
int i = 0;
for (i=0;i<N+M;i++) //打印
{
printf("%d ",arrc[i]);
}
while(1)
{
}
return 0;
}
展开全部
void fun(int *a, int *b, int *c) {
int i = 0,j = 0,temp;
while (i < M) c[j++] = b[i++];
i = 0;
while (i < N) c[j++] = a[i++];
for (i = M; i < (N + M); i++) {
temp = c[i];
for (j = i-1; c[j] < temp; j--) {
c[j+1] = c[j];
c[j] = temp;
}
}
}
int i = 0,j = 0,temp;
while (i < M) c[j++] = b[i++];
i = 0;
while (i < N) c[j++] = a[i++];
for (i = M; i < (N + M); i++) {
temp = c[i];
for (j = i-1; c[j] < temp; j--) {
c[j+1] = c[j];
c[j] = temp;
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
int i = N + M;
int j = 0;
int k = 0;
int m = 0;
for (j=0;j<i;j++) //把a , b的值 放到 c中
{
if (j<N)
{
c[j] = a[j];
continue;
}
c[j] = b[k];
k++;
}
k = N+M;
while(k) //给c 降序
{
for (j=0;j<i;j++)
{
if (j+1>i)
{
break;
}
if (c[j]<c[j+1])
{
m = c[j];
c[j] = c[j+1];
c[j+1] = m;
}
}
k--;
}
return c;
int j = 0;
int k = 0;
int m = 0;
for (j=0;j<i;j++) //把a , b的值 放到 c中
{
if (j<N)
{
c[j] = a[j];
continue;
}
c[j] = b[k];
k++;
}
k = N+M;
while(k) //给c 降序
{
for (j=0;j<i;j++)
{
if (j+1>i)
{
break;
}
if (c[j]<c[j+1])
{
m = c[j];
c[j] = c[j+1];
c[j+1] = m;
}
}
k--;
}
return c;
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询