Home › Forums › C Programming › exercise › Reply To: exercise
October 10, 2007 at 7:35 am
#3127
S.Thananchayan
Participant
This one was interesting.
I ended up with this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #include <iostream><br /> using namespace std;<br /> #include <vector><br /> int main()<br /> {<br /> cout << "You are only allowed to enter 5" << endl ;<br /> std::vector<int>::iterator iter;<br /> std::vector</int><int> intVector;<br /> int z;<br /> cout << "enter a valuen";<br /> cin >>z;<br /> if (z <5)<br /> return main();<br /> <br /> if (z >5)<br /> return main();<br /> else<br /> for (int i=0; i<z; ++i)<br /> intVector.push_back(z - i);<br /> reverse(intVector.begin(), intVector.end());<br /> for (int i=1; i<z+1; ++i)<br /> intVector.push_back(z - i);<br /> intVector.pop_back();<br /> reverse(intVector.begin(), intVector.end());<br /> for (iter = intVector.begin(); iter != intVector.end(); ++iter)<br /> cout << *iter;<br /> cout << endl;<br /> reverse(intVector.begin(), intVector.end());<br /> for (iter = intVector.begin() +1; iter != intVector.end()-1; ++iter)<br /> cout << *iter;<br /> cout << endl;<br /> for (iter = intVector.begin() +2; iter != intVector.end()-2; ++iter)<br /> cout << *iter;<br /> cout << endl;<br /> for (iter = intVector.begin() +3; iter != intVector.end()-3; ++iter)<br /> cout << *iter;<br /> cout << endl;<br /> for (iter = intVector.begin() +4; iter != intVector.end()-4; ++iter)<br /> cout << *iter;<br /> cout << endl;<br /> return (0);<br /> }</int></vector></iostream> |