#include
void main()
{
int i, x, a[10], res;
int search(int *, int, int);
for(i=0; i<10; i++) scanf("%d", &a[i]);
scanf("%d", &x);
//请在两条星线之间填入相应的代码, 调用search函数,查找整数x在数组a中的位置。
/*************************************************************************/
res=search(a,10,x);
/*************************************************************************/
if(res==-1)printf("Not found\n");
else printf("The position is %d\n", res);
}
//定义一个函数search(int list[],int n,int x),在数组list中查找元素x,若找到则
//返回相应下标,否则返回-1,其中:n为list数组中的元素个数。
int search(int *p, int n, int x)
{
int i, pos;
//请在两条星线之间填入相应的代码, 查找x在指针p指向的含n个元素的数组中的位置
//要求:利用指针方法来处理。
/*************************************************************************/
pos=-1;
for(i=0;i
if(x==*p)
{
pos=i;
break;
}
p++;
}
/*************************************************************************/
return pos;
}
对程序头疼的飘过!