Skip to content

Commit

Permalink
排列数和组合数计算器
Browse files Browse the repository at this point in the history
  • Loading branch information
PangXitong committed Apr 20, 2024
1 parent 83f30f8 commit 4d61045
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
Binary file modified blog/tool/.DS_Store
Binary file not shown.
69 changes: 69 additions & 0 deletions blog/tool/AC.html
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>
5 changes: 5 additions & 0 deletions blog/tool/ToolList.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ <h1>工具列表</h1>
<a href="./Calculator/index.html">科学计算器</a>
<p class="description">开源科学计算器<a target="_blank" href="https://github.com/PitPik/CalcSS3">CalcSS3</a>(2024.3.23)</p>
</div>

<div class="repository">
<a href="./AC.html">排列数和组合数计算器</a>
<p class="description">排列数和组合数计算器(2024.4.20)</p>
</div>
</div>
<div style="bottom: 50px;text-align: center;margin-top: 80px;">
<a target="_blank" href="./blog/open.html"><a href="https://ipw.cn/ssl/?site=oldsai.cn" title="本站支持SSL安全访问" target='_blank'><img style='display:inline-block;vertical-align:middle' alt="本站支持SSL安全访问" src="../images/ssl-s1.svg"></a>
Expand Down
1 change: 1 addition & 0 deletions map.html
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ <h2 style="font-size:40px;">庞玺桐的博客的导览页面</h2>
<li>网页导览<a href="./blog/tool/map.html"target="_blank">./map.html</a></li>
<li>随机数<a href="./blog/tool/random_number.html"target="_blank">./random_number.html</a></li>
<li>科学计算器<a href="./blog/tool/Calculator/index.html"target="_blank">./Calculator/index.html</a></li>
<li>排列数和组合数计算器<a href="./blog/tool/AC.html"target="_blank">./AC.html</a></li>
</ul>
<li>页面<a href="./blog/more.html"target="_blank">./page</a></li>
<ul>
Expand Down

0 comments on commit 4d61045

Please sign in to comment.