1. ## Digits reverse

i have write a program digits reverse.......but prob here....how to gets output with negatif number....

e.g
input : -123456
output : -654321

this my program

Code:
```#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{
int a,b,c,d,e,f,sum,find=0;

cout << "Enter an integer digits: ";
cin >> sum;

a = (sum % 10);

b = (sum % 100);
b = b / 10;

c = (sum % 1000);
c = c / 100;

d = (sum % 10000);
d = d / 1000;

e = (sum % 100000);
e = e / 10000;

f = (sum % 1000000);
f = f / 100000;

if (sum<10)
{
cout << "The Reverse Order is   : " << endl;
cout << a << endl;
}
else if (sum<100)
{
cout << "The Reverse Order is   : ";
cout << a << b << endl;
}
else if (sum<1000)
{
cout << "The Reverse Order is   : ";
cout << a << b << c << endl;
}
else if (sum<10000)
{
cout << "The Reverse Order is   : ";
cout << a << b << c << d << endl;
}
else if (sum<100000)
{
cout << "The Reverse Order is   : ";
cout << a << b << c << d << e <<  endl;
}
else if (sum<1000000)
{
cout << "The Reverse Order is   : ";
cout << a << b << c << d << e << f << endl;
}

else if ((sum<0) && (sum<10))
{
cout << "The Reverse Order is   : ";
cout <<"-"<< a << endl;
}

cout << "\n\n\n\n";

system("PAUSE");
return 0;

}```

2. Code:
```/* ...Before the parsing... */

if (sum < 0) {
sum *= -1;
isNegetive = true;

/* ... After the parsing ... */

if (isNegetive)
sum *= -1;
// Or if you wish...
// cout << a * -1 << b ...```

3. i have write a program digits reverse
You can do the whole program in only a few lines that will handle any size number if you turn the number into a string type and then reverse the string.

4. Originally Posted by SlyMaelstrom
Code:
```/* ...Before the parsing... */

if (sum < 0) {
sum *= -1;
isNegetive = true;

/* ... After the parsing ... */

if (isNegetive)
sum *= -1;
// Or if you wish...
// cout << a * -1 << b ...```
input :-123456
output:-6-5-4-3-2-1

7stud....
im a beginner....so i write the program how i understand...
u have any tips??...i appreciate it...thanks

5. Originally Posted by mufanz
input :-123456
output:-6-5-4-3-2-1
Congratulations, all that means is you implemented it wrong. You're only supposed to multiply the leading digit a by -1.

6. thanks....program success

7. Code:
```#include <iostream>
#include <string>
#include <sstream> //ostringstream
using namespace std;

int main()
{
int num = 1234;

ostringstream myOutputString; //creates a special kind of variable(see below)

myOutputString<<num;
//myOutputString works just like 'cout'
//except you're outputting 'num' into a variable
//instead of to the console window.
//You can output any type into the variable.

string myString = myOutputString.str();
//the str() function returns a string that contains
//whatever is inside myOuputString

cout<<"This is now a string: "<<myString<<endl;

//strings have many functions for manipulating them,
//but you can just use a string's length() function and a for
//loop to reverse a string.  A string can be treated just like
//and array of characters.

string reversed;

for(int position = myString.length() - 1; position >= 0; position--)
{
reversed = reversed + myString[position];
}

cout<<reversed<<endl;

return 0;
}```