Home Forums C Programming exercise Reply To: exercise

#3127
S.Thananchayan
Participant

This one was interesting.
I ended up with this:

#include 
using namespace std;
#include
int main()
{
 cout << "You are only allowed to enter 5" << endl  ;
 std::vector::iterator iter;
 std::vector
intVector;
 int z;
 cout << "enter a valuen";
 cin >>z;
 if (z <5)
      return main();
      
 if (z >5)
  return main();
 else
  for (int i=0; i    intVector.push_back(z - i);
 reverse(intVector.begin(), intVector.end());
 for (int i=1; i   intVector.push_back(z - i);
 intVector.pop_back();
 reverse(intVector.begin(), intVector.end());
 for (iter = intVector.begin(); iter != intVector.end(); ++iter)
  cout << *iter;
 cout << endl;
 reverse(intVector.begin(), intVector.end());
 for (iter = intVector.begin() +1; iter != intVector.end()-1; ++iter)
  cout << *iter;
 cout << endl;
 for (iter = intVector.begin() +2; iter != intVector.end()-2; ++iter)
  cout << *iter;
 cout << endl;
 for (iter = intVector.begin() +3; iter != intVector.end()-3; ++iter)
  cout << *iter;
 cout << endl;
 for (iter = intVector.begin() +4; iter != intVector.end()-4; ++iter)
  cout << *iter;
 cout << endl;
 return (0);
}