Solve it using c++?

Write a program that reads ten integers and displays them in the reverse of the order in which they were read.Only use array.
How much have you written so far?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <array>
#include <iostream>

int main()
{
    std::array<int, 10> numbers;

    for (int &i: numbers)
        if (!(std::cin >> i))
            throw "catch this!";

    for (auto cit = numbers.crbegin(); cit != numbers.crend(); ++cit)
        std::cout << *cit << ' ';

    std::cout << std::endl;
}
std::array is not an array. So the code can look the following way

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>

int main()
{
   const size_t N = 10;
   int a[N];

   for ( size_t i = 0; i < N; i++ ) std::cin > a[i];

   for ( size_t i = N; i != 0; ) std::cout << a[--i] << ' ';
   std::cout << std::endl;

   return ( 0 );
}
Last edited on
Topic archived. No new replies allowed.