1. 程式人生 > >查詢一組資料中符合斐波那契數列的數

查詢一組資料中符合斐波那契數列的數

<!DOCTYPE html>
<html>
<head>
	<title>菲波那切數列</title>
	<meta charset="utf-8">
	<script type="text/javascript" src="jquery-2.1.1.min.js"></script>
</head>
<body>
	<script type="text/javascript">
		var x = 0;
		var y = 1;
		var z = x + y;
var arr = [1,3,4,5,6,987,7,8,100,200,233,765,377,1596,1569,1597]; var arr1 = []; document.write("斐波那契額:") for(var i = 0; i < 1000; i++){ x = y; y = z; z = x + y; if (x < 2000) { document.write(x + ","); arr1.push(x); } } document.write("<hr/>"+"重合的數字:"
) for(var i = 0; i < arr.length; i++){ for(var j = 0; j < arr1.length; j++){ if (arr[i] == arr1[j]) { document.write(arr[i] + ",") } } }
</script> </body> </html>