#include <stdio.h>
#define M 5
#define N 4
void maoPao(int *, int, int);
void main()
{
int a[M], b[N], c[M + N], i, j;
printf("請輸入a的元素:
");
for (i = 0; i < M; i++)
scanf("%d", &a[i]);
maoPao(a, M, 1);
printf("a的元素升序後:
printf("%4d", a[i]);
printf("
printf("請輸入b的元素:
for (i = 0; i < N; i++)
scanf("%d", &b[i]);
maoPao(b, N, 0);
printf("b的元素降序後:
printf("%4d", b[i]);
for (i = 0, j = 0; i < N + M; i++)
if (i >= M)
c[i] = b[j++];
else
c[i] = a[i];
}
printf("C陣列的元素:
for (i = 0; i < M + N; i++)
printf("%4d", c[i]);
maoPao(c, M + N, 0);
printf("C陣列降序後:
for (i = 0; i < N + M; i++)
getchar();
return 0 ;
//zt = 0 時為降序, = 1 時升序,t 為數量
void maoPao(int *p, int t, int zt)
int i, j, temp;
for (i = 0; i < t - 1; i++)
for (j = 0; j < t - 1 - i; j++)
if (zt == 0)
if (p[j] > p[j + 1])
temp = p[j];
p[j] = p[j + 1];
p[j + 1] = temp;
if (p[j] < p[j + 1])
#include <stdio.h>
#define M 5
#define N 4
void maoPao(int *, int, int);
void main()
{
int a[M], b[N], c[M + N], i, j;
printf("請輸入a的元素:
");
for (i = 0; i < M; i++)
scanf("%d", &a[i]);
maoPao(a, M, 1);
printf("a的元素升序後:
");
for (i = 0; i < M; i++)
printf("%4d", a[i]);
printf("
");
printf("請輸入b的元素:
");
for (i = 0; i < N; i++)
scanf("%d", &b[i]);
maoPao(b, N, 0);
printf("b的元素降序後:
");
for (i = 0; i < N; i++)
printf("%4d", b[i]);
printf("
");
for (i = 0, j = 0; i < N + M; i++)
{
if (i >= M)
c[i] = b[j++];
else
c[i] = a[i];
}
printf("C陣列的元素:
");
for (i = 0; i < M + N; i++)
printf("%4d", c[i]);
printf("
");
maoPao(c, M + N, 0);
printf("C陣列降序後:
");
for (i = 0; i < N + M; i++)
printf("%4d", c[i]);
getchar();
return 0 ;
}
//zt = 0 時為降序, = 1 時升序,t 為數量
void maoPao(int *p, int t, int zt)
{
int i, j, temp;
for (i = 0; i < t - 1; i++)
for (j = 0; j < t - 1 - i; j++)
{
if (zt == 0)
{
if (p[j] > p[j + 1])
{
temp = p[j];
p[j] = p[j + 1];
p[j + 1] = temp;
}
}
else
{
if (p[j] < p[j + 1])
{
temp = p[j];
p[j] = p[j + 1];
p[j + 1] = temp;
}
}
}
}