plz help me on this question.....

1 2 3
4 5 6
7 8 9

how i can swap this like this

3 2 1
6 5 4
9 8 7

plz soon.......

Recommended Answers

All 8 Replies

Read three integers at a time then print them back out in reverse order.

programme example....

Sure -- here's one. If you are asking me to do your homework for you then you can forget it.

#include <iostream>
using std::cout;
using std::cin;

int main()
{
  // pur your code here
}

Maybe some psuedo-code will start you up :

//assuming array column size is 3
function mySwap(Array2D array){
 for row := 0 to array.length DO
     swap(array[0],array[2])
}

And if you want it more general then you can do something like so :

function mySwap(Array2D array){
 for row := 0 to array.length DO
    for colStart := 0, colEnd = array[row].length-1 until colStart < colEnd
      swap(array[colStart],array[colEnd])
      increase colStart and decrease colEnd
}

Or just something simple like this: Note that vectors and swapping are not needed.

For each line in the input file
    Read a line into variables a, b and c
    print variables c, b and a

One temp variable.

a = temp

b = a

b = temp

@Red: you posted the correct solution to the wrong problem.The solution to the problem does not involve swapping the value of any variables.

@Red: you posted the correct solution to the wrong problem.The solution to the problem does not involve swapping the value of any variables.

Well, the OP isn't too clear. All he said was "How do I swap this for that?"

Perhaps I could offer more help if the OP could clarify what exactly he's doing and what he's working with. Input? Variables? Arrays? The question seems very incomplete. I assumed the OP was working with variables since such practices with variable tend to be elementary programming, and the utter lack of context leads to me to believe he is working with some of his very first programs.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.