题目内容:
请编写函数proc(),该函数的功能是:删去一维数组中所有相同的数,使之只剩一个。数组中的数已按由小到大的顺序排列,甬数返回删除后数组中数据的个数。 例如,若一维数组中的数据是:
1 1 2 2 2 3 4 4 5 6 6 6 6 7 7 8
9 9 10 10 10 10
删除后,数组中的内容应该是:
1 2 3 4 5 6 7 8 9 10
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
#define M 80
int proc(int a[],int n)
{ }
void main()
{
int arr[M]一{1,1,2,2,2,3,4,4,5,6,6,6,6,7,7,
8,9,9,10,10,10,10},i,n=22;
printf("The original data:\n");
for(i=0;i<n;i++)
printf("%3d",arr[i]);
n=proc(arr,n):
printf("\n\nThe data after deleted
:\n");
for(i=0;i<n;i++)
printf("%3d",arr[i]);
printf("\n\n");
}
参考答案:
答案解析: