【发布时间】:2019-02-13 05:48:12
【问题描述】:
给定代码的输出应该是数组中元素的索引号,但我没有得到预期的输出。
这是我的代码:
int main() {
int n, a, b;
int arr[100];
cout << "Enter the size of array";
cin >> n;
cout << "Enter the number to find";
cin >> a;
cout << "Enter elements in array";
for (int i = 0; i < n; i++)
cin >> arr[n];
for (int i = 0; i < n; i++) {
if (arr[n] == a) {
cout << n;
} else
n++;
}
return 0;
}
【问题讨论】:
-
你应该一次又一次地调试你的代码!之后就可以发帖了!你当然不是新手!!