Help with storing numbers in arrays

Hi so I am learning about arrays, I just learned how to declare one that holds 5 number: a[5];
but how can i use a for loop to put numbers into the array? All the array examples i see already declare number into the array like a[5]={5,2,3,1,1] So how can i do i with a for loop? please help
Are you reading input from the console (user) in your loop? If so, try this...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
using namespace std;

int main()
{
  int a[5];
  int aNum;

  for (int i=0; i < 5; ++i)
  {
	cin >> aNum;
	a[i] = aNum;
  }

  return 0;
}


If not, maybe this...

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
using namespace std;

int main()
{
  int a[5];

  for (int i=0; i < 5; ++i)
	a[i] = i;

  return 0;
}
Topic archived. No new replies allowed.