<script type = "text/javascript">
var input;
var rev = 0;
input=window.prompt ("Please enter a 5-digit number to be reversed.");
input = input * 1;
while (input > 0)
{
rev *= 10;
rev += input % 10;
input /= 10;
}
document.write ("Reversed number: " + rev);
</script>
The Fibonacci sequence uses recursion to derive answers. It is defined as: F0 = 0 F1 = 1 Fn = F(n - 1) + F(n -2) To have this sequence printed by a php script use the following: function fibonacci($n) { if($n 1) return 1; //F1 else return fibonacci($n - 1) + fibonacci($n - 2); //Fn } This recursive function will print out the Fibonacci number for the integer n. To make it print out all the numbers in a particular set add this to your script. for($i = 0; $i < 15; $i++) { echo fibonacci($i) . "<br />"; } So your final result would look like. <?php function fibonacci($n) { if($n 1) return 1; else return fibonacci($n - 1) + fibonacci($n - 2); } for($i = 0; $i < 15; $i++) { echo fibonacci($i) . "<br />"; } ?>
Just generate the Fibonacci numbers one by one, and print each number's last digit ie number%10.
CLS a = 0 b = 0 FOR i = 1 TO 10 IF a = 0 THEN f = 1 END IF PRINT f b = a a = f f = a + b NEXT i END from : Parth jani parthjani7@yahoo.com
write a program to print the series 1/12+1/22+.........+1/n2 ?
#include<iostream> unsigned fib (unsigned term, unsigned a=0, unsigned b=1) { if (term<1) return a; return fib (--term, a+b, a); } int main() { std::cout << "Fibonacci (1000th term): " << fib (1000) << std::endl; }
The Fibonacci sequence uses recursion to derive answers. It is defined as: F0 = 0 F1 = 1 Fn = F(n - 1) + F(n -2) To have this sequence printed by a php script use the following: function fibonacci($n) { if($n 1) return 1; //F1 else return fibonacci($n - 1) + fibonacci($n - 2); //Fn } This recursive function will print out the Fibonacci number for the integer n. To make it print out all the numbers in a particular set add this to your script. for($i = 0; $i < 15; $i++) { echo fibonacci($i) . "<br />"; } So your final result would look like. <?php function fibonacci($n) { if($n 1) return 1; else return fibonacci($n - 1) + fibonacci($n - 2); } for($i = 0; $i < 15; $i++) { echo fibonacci($i) . "<br />"; } ?>
Just generate the Fibonacci numbers one by one, and print each number's last digit ie number%10.
CLS a = 0 b = 0 FOR i = 1 TO 10 IF a = 0 THEN f = 1 END IF PRINT f b = a a = f f = a + b NEXT i END from : Parth jani parthjani7@yahoo.com
write a program to print the series 1/12+1/22+.........+1/n2 ?
The Fibonacci series is a sequence of numbers, with the first two defined as 0 and 1, and all following numbers defined as the sum of the two previous numbers. The following python program asks a user how many Fibonacci numbers they want calculated, then calculates them. NOTE: This site removes formatting from answers. Replace (tab) with a tab, or four spaces. #!/usr/bin/python print("This program finds Fibonacci numbers.") answer = "y" while answer == "y": (tab)print("How many terms would you like?") (tab)n = int(input(": ")) (tab)a = 0 (tab)b = 1 (tab)for i in range(0,n): (tab)(tab)print(str(a) +",") (tab)(tab)c = a + b (tab)(tab)a = b (tab)(tab)b = c (tab)print("Would you like to run again? (y/n)") (tab)answer = input(": ")
Q.1 Write a program to print first ten odd natural numbers. Q.2 Write a program to input a number. Print their table. Q.3 Write a function to print a factorial value.
#include<iostream> unsigned fib (unsigned term, unsigned a=0, unsigned b=1) { if (term<1) return a; return fib (--term, a+b, a); } int main() { std::cout << "Fibonacci (1000th term): " << fib (1000) << std::endl; }
<html> <head> <script type="text/javascript"> function series() { var i=1 while(i<=10) { document.write(i+"<br>") i=i+2 } } </script> </head> <body> <form action="#" name=f1> <input type=button value="generate series" onclick="series()"> </form> <br><span id="outtab"></span> </body> </html>
If you have the series stored in an array, you loop through the array and print each array element in turn. Another possibility is to print out the numbers in the series as you generate them. In that case, you may not need to store anything (depending on the series, of course).
You can call the Script like this, <script type="text/javascript" src="perl_script.pl"></script> So you just replace a regular Javascript Call ( .js ) with the .pl Script. Inside the Perl Script you will have to use embraced Javascript Functions / Code, f.e. like print "document.write.('Hello World');";.
to print the Fibonacci series until 100 you can take the input in d to make it run for whatever value you want void main(){ int a,b,c,d; a=0; b=1; c=1; d=100; while(c<d) { printf("%d\n",c); c=a+b; a=b; b=c; } }
//WAP to print fibonacci series using do-while loop.? using System; class Fibonacci { public static void Main() { int a=1,b=1; int sum=0; Console.Write("Enter Limit:"); int n=Int32.Parse(Console.ReadLine()); Console.Write(a); Console.Write(b); do { sum=a+b; a=b; b=sum; Console.Write(sum); } while(sum<n); } } By-Vivek Kumar Keshari