forked from shreyaj1/Hacktober-fest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDynamic-Array-Input.cpp
More file actions
26 lines (21 loc) · 1.04 KB
/
Copy pathDynamic-Array-Input.cpp
File metadata and controls
26 lines (21 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*
* SHaDeX0
* 09 - 10 - 2021 (Saturday)
* Dynamic Input for int array
*/
#include <iostream>
using namespace std;
int main() {
int arr[100], size = 0; //Declaring an integer array and variable to track the size of the array
cout << "Instructions: Input the elements of array as much as you want, when you want to stop enter '-32768' without quotes.";
cout << "\nEnter the elements of the array:\n";
while (arr[size - 1] != -32768) { //Checking if the last input is '-32768' till then keep on taking the input
cin >> arr[size++]; //Incrementing size for inserting the element in the next position of the array
}
size--; //Decrementing size as the last element in the array will be '-32768' which is not a part of the user desired array
cout << "\nYour array:\n";
for (int i = 0; i < size; i++) { //Printing the array
cout << arr[i] << "\t";
}
return 0;
}