Answer to Question #272012 in C++ for Judes

Question #272012

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

1
Expert's answer
2021-11-27T02:33:54-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS