Who to use arry in loop | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
- 1

Who to use arry in loop

11th Oct 2016, 3:48 PM
Vaibhav Mehta
Vaibhav Mehta - avatar
5 Réponses
+ 1
if you know the size of the array you can use every loop, but the for loop is the most easier to understand. little example: int main(){ int array[8]; int number; for(int i = 0; i < 8 ; i++ ){ cout<<"give a number to add in the array: "; cin >> number; array[i] = number; } cout<<"Elements in the array: "; for(int i = 0; i < 8; i++){ cout<<array[i]; }
11th Oct 2016, 5:06 PM
Hector Sulbaran
Hector Sulbaran - avatar
0
to print elements in an array of 5 elements u can do like this int arr[5]; for(int i =0;i<5;i++){ cout<<arr[i]<<endl; }
11th Oct 2016, 4:57 PM
Prabhakar Jha
Prabhakar Jha - avatar
0
what will be the output
11th Oct 2016, 5:01 PM
Vaibhav Mehta
Vaibhav Mehta - avatar
0
op:- elements of the array one by one after using endl output will be a[0] a[1] a[2] a[3] a[4]
11th Oct 2016, 5:03 PM
Prabhakar Jha
Prabhakar Jha - avatar
0
thxx.
11th Oct 2016, 5:05 PM
Vaibhav Mehta
Vaibhav Mehta - avatar