程式碼示例:
//呼叫函式trim就行了
#include<stdio.h>
void trim(int arr[],int *pn)
{
int i,j,k;
for(i=0;i<*pn;i++)
for(j=i+1;j<*pn;)
if(arr[i]==arr[j])
for(k=j+1;k<*pn;k++)
arr[k-1]=arr[k];
(*pn)--;
}
else
j++;
int main()
inti,n=20,arr[20]={12,12,12,2,2,20,365,700,1001,366,12,12,50,50,50,100,525,700,700,700};
for(i=0;i<n-1;i++)
printf("%d ",arr[i]);
printf("%d\n",arr[n-1]);
trim(arr,&n);
return 0;
程式碼示例:
//呼叫函式trim就行了
#include<stdio.h>
void trim(int arr[],int *pn)
{
int i,j,k;
for(i=0;i<*pn;i++)
{
for(j=i+1;j<*pn;)
{
if(arr[i]==arr[j])
{
for(k=j+1;k<*pn;k++)
arr[k-1]=arr[k];
(*pn)--;
}
else
j++;
}
}
}
int main()
{
inti,n=20,arr[20]={12,12,12,2,2,20,365,700,1001,366,12,12,50,50,50,100,525,700,700,700};
for(i=0;i<n-1;i++)
{
printf("%d ",arr[i]);
}
printf("%d\n",arr[n-1]);
trim(arr,&n);
for(i=0;i<n-1;i++)
{
printf("%d ",arr[i]);
}
printf("%d\n",arr[n-1]);
return 0;
}