Arraying 101
by CodeChum Admin
I want you to make an array of numbers for me. All you have to do is make a program that will let me input any random integer in one line. Afterwards, it will then print out all the numbers I've inputted, backwards, on separate lines.
Care to do that for me?
Input
The first line contains the size of the array.
The next line contains the integers separated by a space.
5
1·64·32·2·11
Output
Multiple lines containing integers on each.
11
2
32
64
1
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int sz;
cout << "Please, enter a size of an array: ";
cin >> sz;
int* arr = new int[sz];
cout << "Please, enter values: ";
for (int i = 0; i < sz; i++)
{
cin >> arr[i];
}
reverse(&arr[0], &arr[sz]);
cout << "Output:\n";
for (int i = 0; i < sz; i++)
{
cout << arr[i] << endl;
}
}
Comments
Leave a comment