codescracker


c++

C++ One Dimensional Array Program



« Previous Program Next Program »


One Dimensional Array Program in C++

To print one dimensional array in C++ programming, you have to ask to the user to enter array size and array elements to store all the array elements in one dimensional and then print the array in one dimension using one for loop as shown here in the following program

C++ Programming Code for One Dimensional (1D) Array

Following C++ program ask to the user to enter the array size, then ask to enter the element of the array to store the elements in the array, then finally display the array element on the screen:

/* C++ Program - One Dimensional Array Program */
		
#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();
	int arr[50], n;
	cout<<"How many element you want to store in the array ? ";
	cin>>n;
	cout<<"Enter "<<n<<" element to store in the array : ";
	for(int i=0; i<n; i++)
	{
		cin>>arr[i];
	}
	cout<<"The Elements in the Array is : \n";
	for(i=0; i<n; i++)
	{
		cout<<arr[i]<<" ";
	}
	getch();
}

When the above C++ program is compile and executed, it will produce the following result:

C++ program one dimensional array

Same Program in Other Language

You may like the same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test