program works for positive numbers but not for negative numbers.....can someone help me improve it
# include %26lt;iostream%26gt;
# include %26lt;conio.h%26gt;
using namespace std;
void main ()
{int a;
cout%26lt;%26lt;"Enter the number: " ;
cin%26gt;%26gt;a;
while(a!=0)
{ cout%26lt;%26lt;a%10;
a=a/10;
} getch();
}
C++ reverse inputted digits including negative for ex...-7564(4657, without negative sign)?
after cin%26gt;%26gt;a;
add these lines
a=a*a;
a=sqrt(a);
and add the header %26lt;math.h%26gt;
Reply:after cin%26gt;%26gt;a; add 'if(a%26lt;0) a=a*-1;'.
was this some kind of hmework? sounds too easy for a homework either..
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment