-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
83f30f8
commit 4d61045
Showing
4 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>排列数和组合数计算器</title> | ||
<style> | ||
body { | ||
font-family: Arial, sans-serif; | ||
margin: 20px; | ||
} | ||
input[type="number"] { | ||
width: 100px; | ||
margin-right: 10px; | ||
} | ||
button { | ||
padding: 10px 20px; | ||
background-color: #007bff; | ||
color: #fff; | ||
border: none; | ||
cursor: pointer; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h2>排列数和组合数计算器</h2> | ||
<div> | ||
<label for="n">总数 (n):</label> | ||
<input type="number" id="n"> | ||
</div> | ||
<div> | ||
<label for="r">选取数量 (r):</label> | ||
<input type="number" id="r"> | ||
</div> | ||
<button onclick="calculatePermutation()">计算排列数</button> | ||
<button onclick="calculateCombination()">计算组合数</button> | ||
<div id="result"></div> | ||
|
||
<script> | ||
function calculatePermutation() { | ||
var n = parseInt(document.getElementById('n').value); | ||
var r = parseInt(document.getElementById('r').value); | ||
|
||
var permutation = factorial(n) / factorial(n - r); | ||
|
||
document.getElementById('result').innerHTML = '排列数 (P): ' + permutation; | ||
} | ||
|
||
function calculateCombination() { | ||
var n = parseInt(document.getElementById('n').value); | ||
var r = parseInt(document.getElementById('r').value); | ||
|
||
var combination = factorial(n) / (factorial(r) * factorial(n - r)); | ||
|
||
document.getElementById('result').innerHTML = '组合数 (C): ' + combination; | ||
} | ||
|
||
function factorial(num) { | ||
if (num === 0 || num === 1) { | ||
return 1; | ||
} | ||
for (var i = num - 1; i >= 1; i--) { | ||
num *= i; | ||
} | ||
return num; | ||
} | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters