Tuesday 19 February 2013

palindrome


Write a program for PALINDROME  using DO-WHILE loop

<html>
<script language="javascript">
var a;
var b=0;
var temp;
a=parseInt(prompt("enter a no."));
temp=a;
do
{
b=b*10;
b=b+parseInt(a%10);
a=parseInt(a/10);
}while(a>0);
document.write(b)
if(temp==b)
{
 document.write("the given no is palindrome");
}
else
{
 document.write("the given no is not a palindrome");
}
</script>
</html>

output

enter a no:
1221
the given no is palindrome

enter a no:
1251
the given no is not a palindrome

No comments:

Post a Comment