|
-
October 2nd, 2016, 06:00 PM
#1
Array of 100 elements ranging from 1 to 100
Hello!
I'm trying to create an array of 100 elements, ranging from 1 to 100.
Code:
int main()
{
int arr[100];
// For setting values to elements
for (int i = 0; i < 101; i++)
{
arr[i] = i;
}
// For getting values from elements
for (int i = 0; i < 101; i++)
{
cout << arr[i] << endl;
}
return 0;
}
The problem with this code is that in element 0 I have 0, in element 1 I have 1, in element 2 I have 2, and so on.
I need number 1 in element 0, number 2 in element 1, number 3 in element 2, and so on. What am I missing?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|