编写下列函数:bool search(const int a[], int n, int key)
答案:3 悬赏:40 手机版
解决时间 2021-01-25 07:46
- 提问者网友:浮克旳回音
- 2021-01-24 16:26
编写下列函数:bool search(const int a[], int n, int key)a是待搜索的数组,n是数组中元素的数量,key是搜索键。如果key与数组a的某个元素匹配了,那么search函数返回true;否则返回false。要求使用指针算术运算而不是取下标来访问数组元素。
最佳答案
- 五星知识达人网友:罪歌
- 2021-01-24 17:26
#include <stdio.h>
#include <stdbool.h>
bool search(const int a[], int n, int key);
int main(void)
{
}
bool search(const int a[], int n, int key)
{
const int *p;
for(p = a; p < a + n; p++)
{
if(*p == key)
return true;
return false;
}
}
#include <stdbool.h>
bool search(const int a[], int n, int key);
int main(void)
{
}
bool search(const int a[], int n, int key)
{
const int *p;
for(p = a; p < a + n; p++)
{
if(*p == key)
return true;
return false;
}
}
全部回答
- 1楼网友:十年萤火照君眠
- 2021-01-24 18:49
bool search(const int a[], int n, int key){
int *p;
for(p=a;p<a+n;p++)
if (*p==key)
return true;
else return false;
}
- 2楼网友:英雄的欲望
- 2021-01-24 18:32
bool search(const int a[], int n, int key)
{for(int i=0;i<n;i++)
if(a[i]==key)return true;
return false;
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯