主题:求具体指点以下这个fun函数的功能
#include<stdio.h>
#include<stdlib.h>
#define N 20
int fun(int a[],int n,int x)
{
int i,p=0;
a[n]=x;
while(x!=a[p])
p++;
if(n==p)
return -1;
else
{for(i=p;i<n;i++)
a[i]=a[i+1];
return n-1;}
}
main()
{
int w[N]={-3,0,1,5,7,99,10,15,30,90},x,n,i;
n=10;
printf("the original data:\n");
for(i=0;i<n;i++)printf("%5d",w[i]);
printf("\n input x(to delete):");
scanf("%d",&x);
n=fun(w,n,x);
if(n==-1)
printf("*****no be found!***\n\n");
else
{
printf("the data after deleted:\n");
for(i=0;i<n;i++)
printf("%5d",w[i]);
}
system("pause");
return 0;
}
#include<stdlib.h>
#define N 20
int fun(int a[],int n,int x)
{
int i,p=0;
a[n]=x;
while(x!=a[p])
p++;
if(n==p)
return -1;
else
{for(i=p;i<n;i++)
a[i]=a[i+1];
return n-1;}
}
main()
{
int w[N]={-3,0,1,5,7,99,10,15,30,90},x,n,i;
n=10;
printf("the original data:\n");
for(i=0;i<n;i++)printf("%5d",w[i]);
printf("\n input x(to delete):");
scanf("%d",&x);
n=fun(w,n,x);
if(n==-1)
printf("*****no be found!***\n\n");
else
{
printf("the data after deleted:\n");
for(i=0;i<n;i++)
printf("%5d",w[i]);
}
system("pause");
return 0;
}