Write a C++ program which accept elements of an array and then display.

Program Code:
#include<iostream>

using namespace std;
int main()
{
int array[30];
int number;
int i, j,smallest,largest;
cout<<"Enter number of elements you want to insert in array: ";
cin>>number;
cout<<endl;
for(i=0;i<number;i++)
{
cout<<"Element "<<i+1<<":";
cin>>array[i];
cout<<endl;
}
cout<<"The element inserted into the array are :";
for(j=0;j<number;j++)
{
cout<<array[j]<<"  ";
}
return 0;
}

The program output is tested on www.jdoodle.com
Output:

Enter number of elements you want to insert in the array : 5
Element 1: 11
Element 2: 22
Element 3: 33
Element 4: 44
Element 5: 55
The element inserted into the array are :11  22  33  44  55  


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: