Tech Study

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

 

Here are some more example of c++ program for practice :

C++ Program to Enter Month and Print Days.

 C++ program to sort an array in ascending order

c++program to accept two integers and check they are equal or not

C++ program to print day name of week

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

Java Final keyword

Introduction : java final keyword The final keyword present in Java programming language is generally used for restricting the user. …

Read more

C++ Memory Management: new and delete

C++ Memory Management We know that arrays store contiguous and the same type of memory blocks, so memory is allocated …

Read more