0
Can anyone explain the arrays ?
3 Answers
+ 8
On the learn tab at the top of the screen there is a search bar. Enter the term Array here. You should find what you need.
Example of a search result:
https://www.sololearn.com/learn/Java/2148/?ref=app
+ 2
To store the roll no. of a student, we need to store it in a variable:
int rn;
cout<<"Enter student's roll no";
cin>>rn; //user input
Imagine if you've to store the roll no of 10 students, this will be long job if you do this way:
int rn1, rn2, rn3, rn4, rn5, rn6, rn7, rn8, rn9, rn10;
cout<"Enter roll no of 1st student;
cin>>rn1;
cout<<"Enter roll no of 2nd student;
cin>>rn2;
cout<<"Enter roll no of 3rd student";
cin>>rn3;
...and so on till 10th variable.
Therefore, we have arrays, which is basically a variable which can store more than one values. Like this:
int arr[10]; //size is ten bcoz we need to store ten roll no.s
cout<<"Enter roll number of 10 students";
for(int i=0; i<10; i++)
cin>>rn[i];. //loop will run 10 times