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;
}