Write a c++ program which produce the given sequence (in alternative arrangement and reverse order using for loop statement)
Example input: 5
Output: 5, 1, 4, 2, 3, 3, 2, 4, 1, 5
#include<iostream>
#include <vector>
int main()
{
std::vector<int> Element;
int Number;
std::cout << "Please, enter number of sequence elements:" << std::endl;
std::cin >> Number;
std::cout << "Please, enter " << Number << " sequence elements:" << std::endl;
Element.resize(2*Number);
for(int i = 0; i < Number; i++)
{
std::cin >> Element[i];
}
for(int i = 0; i < Number; i++)
{
Element[Number + i] = Element[Number - i -1];
}
std::cout << "New sequence: " << std::endl;
for(int i = 0; i < 2*Number; i++)
{
std::cout << Element[i] << " ";
}
std::cout << std::endl;
return 0;
}
Comments
Leave a comment