0
C++ related problem
How to take input in array c++, plz help me 😭😭
4 ответов
+ 3
//Driver program for taking input(element) for an array.
int main(){
int size = 5;
int arr[size];
for (int i = 0; i < size; i++) {
cout << "Enter array element: ";
cin >>arr[i];
}
cout << "The array elements are:";
for (int i = 0; i < size; i++) {
cout << arr[i] << " ";
}
return 0;
}
+ 3
int main() {
int arr[5]{};
for(int i=0;i<5;i++){
cin>>arr[i];
cout<<arr[i]<<' ';
}
cout<<'\n'<<arr[3]<<'\n';
}
+ 2
use cin for input
for eg.
int main(){
int x;
cin>>x;
cout<<x;
}
+ 2
You can use a loop and take input in every single variable of the array. If you use a loop, your program time complexity is O(n) . You need to continue your loop size time of that array. In C++ vectors is more useful than arrays.