Program  to store elements in an array and print them.

Here, we have a basic program example to store and print elements in an array using different languages. This program is created in c language, c++, Java, and Python.

Code to store and print array elements in C language

#include <stdio.h>
void  main()
{

    int i,n;
       printf("\n\nEnter the size of the array\n");
       scanf("%d",&n);
   int arr[n];
    printf("Input elements in the array :\n");
    for(i=0; i<n; i++)
    {
	    printf("element - %d : ",i);
        scanf("%d", &arr[i]);
    }

    printf("\nElements in array are: ");
    for(i=0; i<n; i++)
    {
        printf("%d  ", arr[i]);
    }
    printf("\n");
}

Code to store and print array elements in C++ language

#include <iostream>
using namespace std;

int main()
{
   int i,n;
       cout<<"\nEnter the size of the array\n";
       cin>>n;
   int arr[n];
    cout<<"Input elements in the array :\n";
    for(i=0; i<n; i++)
    {
	    cout<<"element " << i <<" - ";
        cin>>arr[i];
    }

    cout<<"\nElements in array are:\n ";
    for(i=0; i<n; i++)
    {
        cout<<arr[i]<<endl;
    }
    cout<<"\n";
}

Code to store and print array elements in Python language

a=[]
n=int(input("Enter the size of the array: "))
print("Input elements in the array :")
for i in range(0,n):
    l=int(input())
    a.append(l)
print("Elements in array are:", a)

Code to store and print array elements in Java language

import java.util.*;
public class arrays
{
  public static void main(String[] args)
   {
     int n;
     Scanner sc = new Scanner(System.in);
     System.out.print("Enter size of the array : ");
     n=sc.nextInt();

    int[] arr = new int[n];

    System.out.println("Enter the elements of the array: ");
    for(int i=0; i<n; i++)
      {
       arr[i]=sc.nextInt();
       }
    System.out.println("Array elements are: ");
    for(int i=0; i<n; i++)
     {
       System.out.println(arr[i]);
      }
   }
}