- 1
Who to use arry in loop
5 Respostas
+ 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];
}
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;
}
0
what will be the output
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]
0
thxx.