how do you print an array out in reverse order? lets say the program prints out the sum of a problem and that sum is 51. how do i get it to say 15, beccause thatwould be the reverse order?

Recommended Answers

All 3 Replies

one way is to use sprintf() to convert the int to a char string then print the string in reverse order.

are you ready to implement a few codes?if yes, then i guess you could do as follows--
say your sum i.e. 51 is stored in the variable x, i.e. x=51, initiate another variable say for instance A, and then follow these steps--
int A, B;
while(A>0)
{
A=x/10;
B=x%10
}
cout<<B<<A;

this loop will work if and only if x is an integer variable.
the working of the loop is as follows- since A is an integer variable, it can only store integer values, so while x/10 remains 5.1, the value stored in A will be 5 and then, B=x%10, the value of B will be 1(Since 51/10 leaves remainder 1)
this code can be changed as per your requirements.....
tell me if it works..........
kanika

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.