Write C++ program to read and print elements of array

Introduction

I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.

#include <iostream>
#define MAX_SIZE 100 //Maximum size of the array
using namespace std;
 
int main()
{
    int arr[MAX_SIZE]; //Declares sizr of array
    int i, num;
    cout<<"Enter size of array: ";
    cin>>num;
 
    cout<<"Enter "<<num<< " elements in the array :";
 
    //Reads size & elements in array
    for(i=0; i<num; i++)
    {
        cin>>arr[i];
    }
 
    //Prints all elements of array
    cout<<"\nElements in array are: ";
    for(i=0; i<num; i++)
    {
        cout<<arr[i]<<"\t";
    }
 
    return 0;
}

Result

Write C++ program to read and print elements of array
Write C++ program to read and print elements of array

Leave a Comment