8:06 a.m.
On yahoo answer, i had to answer question like how to reverse number, so i desided to put it up
the guy who asked fisrt asked for a recursive function, so here it is
<-------C code ------->
#include /math.h>/math.h>/>/math.h>/>/>>/>/math.h>/>/>>/>/>>/>>/>>/>/math.h>/>/>>/>/>>/>>/>>/>/>>/>>/>>/>>/>>/>>/>>/>
#include /stdio.h>/stdio.h>/>/stdio.h>/>/>>/>/stdio.h>/>/>>/>/>>/>>/>>/>/stdio.h>/>/>>/>/>>/>>/>>/>/>>/>>/>>/>>/>>/>>/>>/>
int reverse( int iNumber )
{
if( iNumber >= 10 )
{
return (iNumber % 10) * pow(10, (int)log10((double)iNumber)) + reverse(iNumber / 10);
}
else
{
return iNumber;
}
}
int main()
{
printf ( "%d",reverse(123456789));
}
<------- Java code -------->
int reverse( int pNumber )
{
if( pNumber >= 10 )
{
return (int) ((pNumber % 10) * Math.pow(10, (int)Math.log10((double)pNumber)) + reverse(pNumber / 10));
}
else
{
return pNumber;
}
}
Jean-Michel
NJR-Team
the guy who asked fisrt asked for a recursive function, so here it is
<-------C code ------->
#include
#include
int reverse( int iNumber )
{
if( iNumber >= 10 )
{
return (iNumber % 10) * pow(10, (int)log10((double)iNumber)) + reverse(iNumber / 10);
}
else
{
return iNumber;
}
}
int main()
{
printf ( "%d",reverse(123456789));
}
<------- Java code -------->
int reverse( int pNumber )
{
if( pNumber >= 10 )
{
return (int) ((pNumber % 10) * Math.pow(10, (int)Math.log10((double)pNumber)) + reverse(pNumber / 10));
}
else
{
return pNumber;
}
}
Jean-Michel
NJR-Team
1 Response to "Reverse a number in C and Java"
Post a Comment
Have an opinion say it!