One Dimensional Array Example
Here you will get and learn the example code of one dimensional array example in C++ programming.
This is a simple array program, in which you will learn to declare an array, input elements in an array, and print the elements of array.
Syntax of one dimensional array
datatype array_name[array_size];
For example:
int roll_no[20]; //It can store 20 integer numbers
One Dimensional Array Example of C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | //C++ Simple Array Input and print Output program #include<iostream> using namespace std; int main() { int i,a[10]; //get 10 numbers as input cout<<"\nEnter 10 numbers :"; for(i=0;i<10;i++) { cin>>a[i]; } //print 10 numbers as output cout<<"\n List of numbers are ...\n"; for(i = 0; i<10; i++) { cout<<a[i]<<" "; } } |
Output
Enter 10 numbers : 3
2
4
1
8
6
7
6
9
12
List of numbers are … 3 2 4 1 8 6 7 6 9 12
Check out our other C++ programming Examples