【发布时间】:2020-10-18 13:06:58
【问题描述】:
我知道如何检查数字是否存在于数组中,但不存在于 二维数组中。
请在 2D 中帮助我。
#include<iostream>
using namespace std;
int main()
{
int a[3] = { 4,5,6 };
int b, c;
int x = 1, fact = 1;
cout << "enter no ";
cin >> b;
for (int i = 0; i < 3; i++)
{
if (b == a[i]) {
c = a[i];
break;
}
}
cout << "no entered is present" << endl;
}
【问题讨论】:
-
你真的知道如何检查一维数组吗?无论输入的值是否存在于数组中,您发布的代码都将打印“没有输入”。
-
这里没有二维数组!
-
@MikeCAT 'no' 代表这个程序中的数字
-
@AishaRazzaq 那么应该防止输入的数字不在数组中的时候打印吧?
-
您的问题中的二维数组在哪里?
标签: c++ loops c++11 multidimensional-array data-structures