How to input arrays? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to input arrays?

7th Mar 2017, 5:22 PM
Marry Joy Estacio
Marry Joy Estacio - avatar
4 Answers
+ 3
in c++ you can do the following : write the type of the variables in the array EX.int then write the array name EX.names And add [number of elements] or [] and write = {element1,element2,...) Final EX: int names [2] = {Marry,John};
7th Mar 2017, 5:39 PM
Michael Ehab Mikhail
Michael Ehab Mikhail - avatar
0
value by value, separating values by a space, using files, creating a GUI with a prompt, ..
7th Mar 2017, 5:39 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
0
eso lo puedes hacer con ciclos anidados, por ejemplo: int matriz[10][5]; //10 filas y 5 columnas for(int i=0; i<10; i++) //la variable i controla el ciclo de las filas for(int j=0;j<5; j++) // la variable j controla las columnas { cout<<"Ingrese el valor de la posición "matriz[i][j]; cin>>matriz[i][j]; } Recuerda que los indices de las matrices son igual que los vectores, la primer posición ocupa el indice (0, 0) y la ultima seria (n-1, n-1), es decir, si fuera un arreglo como en el ejemplo la primer posición seria (0, 0) y la ultima seria (9, 4). Espero que esta información sea de ayuda.
7th Mar 2017, 5:42 PM
Eddy
0
set up a for loop and use the same int you used in the for loop, say "i" and put it in place of the number inside the array you want to augment. after that you can treat it like an int. arr [4] (0,1,2,3); for (int i; i<4; i++); arr[i]= // this is where you augment... ps prob. not going to compile if copy and pasted.
7th Mar 2017, 6:34 PM
david schlemmer
david schlemmer - avatar