reverse

can you teach me how to do some program that can print the number 1-10 first five (1-5) and reverse the remaining (6-10)..

ex. output: 1 2 3 4 5 10 9 8 7 6

thanks
Well... I'd rather not give out a solution, but I can give you a really large hint. I'd give a reference to the standard library, but I think it makes more sense if you show that you know how to do it (I'm assuming this is some sort of assignment?). See if this helps! :)

Assuming you have an array with the numbers 1-10...

1
2
3
4
for(int i = 9; i > 4; i--)
{
    //Copy the elements into the last 5 spaces of a different array.
}


EDIT: Forgot to mention something.

-Albatross
Last edited on
int i=1,j=10;
while(i<=10){
if(i <=5)
printf("%d ", i);
else if(j<=6)
printf("%d ", j--);
i++;
}


1
2
3
4
5
#include <iostream>
using namespace std;
main() {
    cout << "1 2 3 4 5 10 9 8 7 6";
}


http://codewall.blogspot.com
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;

int main()
{
  int loop_counter;
  int maxx = 10;
  int last_half = maxx + (maxx/2) + 1;
  for( loop_counter = 1; loop_counter <=maxx; loop_counter++ )
  {
      if( loop_counter <= 5 )
      {
          cout << loop_counter << " ";
      } else {
          cout << last_half - loop_counter << " ";
  }
  }

  cout << "\n";

  return 0;
}

I see full uncommented solutions... how do these help the OP?

I also admit that I kinda misread the problem. :)

-Albatross
I like thecodewall's solution! But, somehow I don't think the OPs teacher will feel the same...

P.S.: Albatross is right Guys. Posting complete solutions to obvious homework problems will not help anyone to learn C++. Especially if you don't even bother to explain your code.
thanks to you guys... :*

I wouldn't be able to verify it as homework on December 30th, but who am I to say so.. heh.

P.S. I wish I had programming classes where I lived... that would be the coolest thing ever. Small town Highschools in Louisiana FTL.
thecodewall... nice program.. hahah
ProgrammingNoob.. its advance study, so boring here at house. so i want to learn more about programming...
if you dont mind can you teach me.. ??



begginers..!!heheh
Topic archived. No new replies allowed.