Pages

Sunday, November 10, 2013

Program 1 (a)

1  a)
        Develop and demonstrate a XHTML file that includes Javascript script
        for the following problems:
         Input   :  A number n obtained using prompt
         Output : The first n Fibonacci numbers


<html >
<head>
<title> Fibonacci Numbers </title>
</head>
<body>
<center>
<h1>Calculating the fibonacci numbers</h1>
<script type="text/javascript">
var n,a=0,b=1,i,c
n=prompt("Enter a number ","")
if(n<=0) alert("Invalid number")
else
{
if(n==1) document.write(a)
else document.write(a+"<br />"+b)
for(i=2;i<n;i++)
{
c=a+b
a=b
b=c
document.write("<br />"+c)
}
}
</script>
</center>
</body>
</html>

No comments:

Post a Comment