C语言中的一道问题、/、、!!!
#include<stdio.h>#defineMAXN10intsearch(intlist[],intn,intx);intmain(){inti,index,n,x...
#include <stdio.h>
#define MAXN 10
int search( int list[], int n, int x );
int main()
{
int i, index, n, x;
int a[MAXN];
scanf("%d", &n);
for( i = 0; i < n; i++ )
scanf("%d", &a[i]);
scanf("%d", &x);
index = search( a, n, x );
if( index != -1 )
printf("index = %d\n", index);
else
printf("Not found\n");
return 0;
}
int search( int list[], int n, int x )
{
int i,index;
for(i=0;i<n;i++){
if (list[i]==x){
index=i;
return i;
}
else{
return -1;
}
}
}
在数组中查找指定元素,,,,哪里错了??? 展开
#define MAXN 10
int search( int list[], int n, int x );
int main()
{
int i, index, n, x;
int a[MAXN];
scanf("%d", &n);
for( i = 0; i < n; i++ )
scanf("%d", &a[i]);
scanf("%d", &x);
index = search( a, n, x );
if( index != -1 )
printf("index = %d\n", index);
else
printf("Not found\n");
return 0;
}
int search( int list[], int n, int x )
{
int i,index;
for(i=0;i<n;i++){
if (list[i]==x){
index=i;
return i;
}
else{
return -1;
}
}
}
在数组中查找指定元素,,,,哪里错了??? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询