+ 1

How can I input data in an array using loop in C++?

If there is an array int x[5] and I'm inputting data by using for(i=0;i<5;i++) { while(i<5) { n=4; n--; } x[i]=n; } is this the correct way or how can I do something like this

30th Sep 2017, 6:23 PM
Aftab Rizvi
Aftab Rizvi - avatar
2 Respuestas
+ 3
bhai go for simplest ~_~ 1. if value is to be assigned by user then /* int arr[5]; cout<<"Enter 5 numbers "; for(i=0;i<5;i++) cin>>arr[i]; */ for printing values again loop for(i=0;i<4;i++) cout<<arr[i]; 2. if value has been set int arr[ ]={1,2,3,4,5}; for(i=0;i<5;i++) cout<<arr[i];
1st Oct 2017, 12:14 PM
Shivam Shandilya😊🙌
Shivam Shandilya😊🙌 - avatar
+ 11
Easiest and more elegant way to do so. int x[5]; for (int &i : x) std::cin >> i;
30th Sep 2017, 6:27 PM
Babak
Babak - avatar