+ 2

Can anyone please explain ARRAYS IN LOOPS ..... Im a beginner .. please

27th Jul 2017, 8:32 AM
Yasir Faiz Ahmed
Yasir Faiz Ahmed - avatar
3 Antworten
+ 3
Arrays in loop usually used for automatically define a new variable for a data type (eg. int). here is example : int main () { int n[ 10 ]; // n is an array of 10 integers // initialize elements of array n to 0 for ( int i = 0; i < 10; i++ ) { n[ i ] = i + 100; // set element at location i to i + 100 } cout << "Element" << setw( 13 ) << "Value" << endl; // output each array element's value for ( int j = 0; j < 10; j++ ) { cout << setw( 7 )<< j << setw( 13 ) << n[ j ] << endl; } return 0; }
27th Jul 2017, 8:47 AM
Muhammad Bagus Zulmi
Muhammad Bagus Zulmi - avatar
+ 1
Array is a set of variables of same data type. Loops are used to iterate a piece of code.
27th Jul 2017, 8:35 AM
G.S.N.V. Suraj
G.S.N.V. Suraj - avatar
+ 1
Think of any array as a list of variables. A loop can allows you to move through that list 1 by 1, accessing each member variable.
27th Jul 2017, 8:36 AM
josh mizzi
josh mizzi - avatar