填空题
以下程序的功能是:删去一维数组中所有相同的数,使之只剩一个。数组中的数已按由小到大的顺序排列,函数返回删除后数组中数据的个数。
例如,若一维数组中的数据是:
2 2 2 3 4 4 5 6 6 6 6 7 7 8 9 9 10 10 10
删除后,数组中的内容应该是:
2 3 4 5 6 7 8 9 10。
请填空。
#include <stdio.h>
#define N 80
int fun (int a[], int n)
int i,j=1;
for(i=1; i<n; i++)
if(a[j-1] (10) a[i])
a[j++]=a[i];
(11)
main()
(int a[N]=(2, 2, 2, 3, 4, 4, 5, 6, 6, 6, 6, 7, 7, 8, 9, 9, 10, 10, 10], i, n=19;
printf("The original data: \n");
for(i=0; i<n; i++)printf("%3d", a[i]);
n=fun(a,n);
printf("\nThe data after deleted: \n");
fori=0; i<n; i++printf("%3d", a[i]); printf("\n\n");
【参考答案】
!=