0

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?

4
Contributors
3
Replies
4
Views
10 Years
Discussion Span
Last Post by kansmish82
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.