Skip to content

Commit 8e5d583

Browse files
committed
added one 1d arrays in cpp
1 parent a4c2d43 commit 8e5d583

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

Diff for: C++/Data-Structures/ARRAYS/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# IGNORE FILES FOR C++
2+
3+
*.o
4+
*.out
5+
*.exe

Diff for: C++/Data-Structures/ARRAYS/1darrays.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* 1 Dimensional Array
3+
*/
4+
#include <iostream>
5+
using namespace std;
6+
int main()
7+
{
8+
int n; //size of the array
9+
cout << "Enter the size of the array" << endl;
10+
cin >> n;
11+
int arr[n]; //decalared 1d array of size n
12+
cout << "Enter the elements of the array" << endl;
13+
for(int i=0;i<n;i++)
14+
{
15+
cin >> arr[i];
16+
}
17+
cout << "Entered array:" <<endl;
18+
for(int i=0;i<n;i++)
19+
{
20+
if(i==n-1)
21+
{
22+
cout << arr[i] << endl;
23+
}
24+
else
25+
{
26+
cout << arr[i]<<" ";
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)