0
For Loop
Hi, I understand how for loops work but when I play with someone and their is a for loop question, I always get it wrong. For example; int arr[] = {5,2,3,7,8} for (int i = 1; i > 10; i++;) { arr [0] += arr [i] } cout << arr [0] << endl; Then it will be what is the output of this code? I know this code is a bit off but I just typed it as quick as i can so you can understand what i am stuck on. Thanks.
5 odpowiedzi
0
it gives garbage value..
see ur code is wrong.
0
like i said i rushed the code so u could understand what im saying.
0
yeh thanks. I understand for loops i just get stuck at these questions in the play section.
0
your code is wrong.. it should be like this.
#include <iostream>
using namespace std;
int main() {
int arr[] = {5,2,3,7,8};
int i;
for (i = 1; i < 5; i++)
{
arr [0] += arr [i];
}
cout << arr [0] << endl;
return 0;
}
0
The question has been answered.