0

C++ related problem

How to take input in array c++, plz help me 😭😭

1st Mar 2024, 9:36 AM
javed Jimi
javed Jimi - avatar
4 Antworten
+ 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; }
2nd Mar 2024, 6:21 AM
Garima Rao
Garima Rao - avatar
+ 3
int main() { int arr[5]{}; for(int i=0;i<5;i++){ cin>>arr[i]; cout<<arr[i]<<' '; } cout<<'\n'<<arr[3]<<'\n'; }
1st Mar 2024, 10:04 AM
Bob_Li
Bob_Li - avatar
+ 2
use cin for input for eg. int main(){ int x; cin>>x; cout<<x; }
1st Mar 2024, 3:47 PM
Alhaaz
Alhaaz - avatar
+ 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.
2nd Mar 2024, 3:50 PM
Sk Sahagir
Sk Sahagir - avatar