Write a simple program user input array in C++/C
#include <iostream>
using namespace std;
void input(int *arr, int n)
{
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}
cout << endl;
}
void output(int *arr, int n)
{
for (int i = 0; i < n; i++)
{
cout << arr[i] << " ";
}
cout << endl;
}
int main()
{
int n;
cout << "Enter the array Size " << endl;
cin >> n;
int arr[n];
cout << "Enter the array element :" << endl;
input(arr, n);
cout << "The array is : ";
output(arr, n);
}
Output is:
Enter the array Size
5
Enter the array element :
1 2 3 4 6
The array is : 1 2 3 4 6
0 Comments