Here's what you need to do:
1.) Assign a number to each element of the array
2.) Print all the elements of the array
There are several things that are wrong with your code:
1.) In the for loop, you're giving a value to
ctr
, and then comparing and incrementing it. However, you use
i
to access the indices of the array. This is incorrect, because:
a.)
i
was never initialized
b.)
i
never changes
2.) The for loop is incorrect to begin with, because you're attempting to print the values from an array that hasn't been initialized.
What you should do, is make one for loop which initializes the array, and then another for loop which prints each elements of the array.
1 2 3 4 5 6
|
const unsigned int size = 100;
int array[size];
for(int i=0; i<size; ++i) {
array[i] = i+1;
}
|
Let's see if you can figure out the rest.