+ 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
2 ответов
+ 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];
+ 11
Easiest and more elegant way to do so.
int x[5];
for (int &i : x)
std::cin >> i;