#include<stdio.h>
#define M 15
int fun( );
int main()
{
int aa[M] = { 1,2,3,3,2,1,1,2,3,4,5,4,3,2,1 }, n = 15, y, k;
scanf("%d", &y);
n = fun(aa, n, y);
for (k = 0; k < n; k++)
printf("%d ", aa[k]);
printf("\n");
return(0);
}
fun(int aa[], int n, int y)
{
int t, i, j;
for (i = 0; i < 15; i++)
if (aa[i] == y)
n--;
for (i = 0; i < 15; i++)
if (aa[i] == y)
for (j =i-1 ; j < 15; j++)
{
t = aa[j + 1];
aa[j + 1] = aa[j];
aa[j] = t;
}
return n;
}
代码如下,如有帮助,请采纳一下,谢谢。
#include<stdio.h>
#define M 15
int fun(int aa[], int n, int y);
int main()
{
int aa[M] = { 1,2,3,3,2,1,1,2,3,4,5,4,3,2,1 }, n = 15, y, k;
scanf("%d", &y);
n = fun(aa, n, y);
for (k = 0; k < n; k++)
printf("%d ", aa[k]);
printf("\n");
return(0);
}
int fun(int aa[], int n, int y)
{
int t, i, j;
for (i = 0; i < 15; i++)
if (aa[i] == y)
n--;
for (i = 0,j= 0; i < 15; i++)
{
if (aa[i] != y)
aa[j++] = aa[i];
}
return n;
}