#include
#define N 15
int fun(int a[])
{
int i,j,k,m=N;
for(i=0;ifor(j=i+1;j if(a[j]==a[i])
{
for(k=j;ka[k]=a[k+1];
m--;i--;
}
return m;
}
void main()
{
int i,k,a[N];
for(i=0;i{
scanf("%d",&a[i]);
if(a[i]<=0)
{
printf("输入的第%d个数不是正整数,请重新输入第%d个数:\n",i+1,i+1);
i--;
}
}
k=fun(a);
for(i=0;iprintf("%d ",a[i]);
printf("\n有效元素个数: %d",k);
}
//运行示例:
#include
#define N 15
int fun(int a[])
{int i,j,k,n=N;
for(i=0;ifor(j=i+1;j if(a[j]==a[i])
{for(k=j;ka[k]=a[k+1];
n--;
j--;
}
return n;
}
int main(void)
{int i,n,a[N];
for(i=0;ido
{scanf("%d",&a[i]);
if(a[i]<=0)printf("请重新输入一个正数:");
}while(a[i]<=0);
printf("数组a中有%d个非重复元素:\n",n=fun(a));
for(i=0;iprintf("%d ",a[i]);
printf("\n");
return 0;
}