Untitled

 avatar
unknown
c_cpp
a year ago
790 B
4
Indexable
#include <iostream>
#include <vector>

std::vector< int > readData()
{
    std::vector< int > result;

    int n = 1;
    int index = 1;
    while( n != 0 )
    {
        std::cout << "Liczba " << index << ": ";
        std::cin >> n;
        result.push_back( n );

        ++index;
    }
    std::cout << "\n\n";

    return result;
}

void printResult( const std::vector< int >& vec )
{
    std::cout << "Liczby w wektorze w odwroconej kolejnosci:\n";
    for( auto it = vec.end() - 1; it != vec.begin() - 1; --it )
    {
        std::cout << *it << ", ";
    }
}

int main()
{
    std::vector< int > vec = readData();

    // Zdjęcie elementu 0, który zawsze występuje na końcu
    vec.pop_back();

    printResult( vec );

    return 0;
}
Editor is loading...
Leave a Comment