填空题
请补充函数proc(),该函数的功能是:删去一维数组中所有相同的数,使之只剩一个。数组中的数已按由小到大的顺序排列,函数返回删除后数组中数据的个数。
例如,若一维数组中的数据是:1 1 2 2 2 3 4 4 5 5 6 6 6 7 7 8 10 10。
删除后,数组中的内容应该是:1 2 3 4 5 6 7 8 10。
注意:部分源程序如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#define M 80
int proc(int arr[],int n)
{
int i,t,j=0;
t=arr[0];
for(i=1;i<n;i++)
if(______)
;
else
{
______;
t=arr[i];
}
arr[j++]=t;
return j;
}
void main()
{
int arr[M]={1,1,2,2,2,3,4,4,5,5,6,6,6,
7,7,8,10,10},i,n=18;
printf('The original data:\n');
for(i=0;i<n;i++)
printf('%4d',arr[i]);
n=proc(arr,n);
printf('\n\nThe data after deleted;
\n');
for(i=0;i<n;i++)
printf('%4d',arr[i]);
printf('\n');
}