Tuesday, 19 February 2013

reverse num

write a java script to display reverse of a given number using WHILE , DO-WHILE  loop

WHILE:

<html>
<script language="javascript">
var a;
var b=0;
a=parseInt(prompt("enter a no."));
while(a>0)
{
b=b*10;
b=b+parseInt(a%10);
a=parseInt(a/10);
}
document.write("The reverse of a given number is:" +b)
</script>
</html> 

OUTPUT

enter a no.
1907
The reverse of a given number is:7091




DO-WHILE:

<html>
<script language="javascript">
var a;
var b=0;
a=parseInt(prompt("enter a no."));
do
{
b=b*10;
b=b+parseInt(a%10);
a=parseInt(a/10);
}while(a>0);
document.write("The reverse of a given number is:" +b)
</script>
</html>

OUTPUT:
enter a no.
3492

the reverse of a given number is:2943