Home » Program to print the elements of an array

Program to print the elements of an array

by Online Tutorials Library

Q. Program to print the elements of an array.

Explanation

In this program, we need to create an array and print the elements present in the array.

Arrays are the special variable that stores multiple values under the same name. A contiguous memory will be allocated to store elements. Elements of the array can be accessed through their indexes.

Program to print the elements of an array

Here, 1, 2, 3, 4 and 5 represent the elements of the array. These elements can be accessed through their corresponding indexes, i.e., 0, 1, 2, 3 and 4.

Algorithm

  1. Declare and initialize an array.
  2. Loop through the array by incrementing the value of i.
  3. Finally, print out each element of the array.

Solution

Python

Output:

Elements of given array:   1 2 3 4 5  

C

Output:

Elements of given array:   1 2 3 4 5  

JAVA

Output:

Elements of given array:   1 2 3 4 5   

C#

Output:

Elements of given array:   1 2 3 4 5  

PHP

Output:

Elements of given array:   1 2 3 4 5  

Next Topic#

You may also like