写一个函数,在指定数组中查询某个数是否存在,如果找到返回true,找不到返回false,
2014-06-20
展开全部
template <class 类模板形参>
bool 判断数值包含(类模板形参* 数组, 类模板形参 值, int 维度)
{
bool 判断(false);
do
{
if (数组[维度] == 值)
{
判断 = true;
break;
}
} while (--维度);
return 判断;
};
int aa[]{1,2,3,4,5,6,7,8,9};
cout << 判断数值包含(aa, 4, 9);
double bb[]{1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8,9.9};
cout << 判断数值包含(bb, 4.04, 9);
bool 判断数值包含(类模板形参* 数组, 类模板形参 值, int 维度)
{
bool 判断(false);
do
{
if (数组[维度] == 值)
{
判断 = true;
break;
}
} while (--维度);
return 判断;
};
int aa[]{1,2,3,4,5,6,7,8,9};
cout << 判断数值包含(aa, 4, 9);
double bb[]{1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8,9.9};
cout << 判断数值包含(bb, 4.04, 9);
展开全部
Public Function find(a() As Integer, x As Integer)
find = False
For i = LBound(a) To UBound(a)
If a(i) = x Then find = True: Exit For
Next i
End Function
find = False
For i = LBound(a) To UBound(a)
If a(i) = x Then find = True: Exit For
Next i
End Function
追问
给了开头
追答
Public Function find(a() As Integer, x As Integer) As Boolean
find = False
For i = LBound(a) To UBound(a)
If a(i) = x Then find = True: Exit For
Next i
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询