<!DOCTYPE html>
	<html lang="vi" xmlns="http://www.w3.org/1999/xhtml" prefix="og: http://ogp.me/ns#">
	<head>
<title>&#91;C++&#93;. Thư Viện Math.h Và Thư Viện Algorithm</title>
<meta name="description" content="&#91;C++&#93;. Thư Viện Math.h Và Thư Viện Algorithm - Savefile - Tin Tức - https&#x3A;&#x002F;&#x002F;tinhocdct.xyz&#x002F;savefile&#x002F;hoat-dong-chuyen-mon&#x002F;c-thu-vien-math-h-va-thu-vien-algorithm-463.html">
<meta name="author" content="TỔ TIN HỌC TRƯỜNG THPT ĐỖ CÔNG TƯỜNG">
<meta name="copyright" content="TỔ TIN HỌC TRƯỜNG THPT ĐỖ CÔNG TƯỜNG [webmaster@tinhocdct.xyz]">
<meta name="robots" content="index, archive, follow, noodp">
<meta name="googlebot" content="index,archive,follow,noodp">
<meta name="msnbot" content="all,index,follow">
<meta name="generator" content="NukeViet v4.0">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta property="og:title" content="&#91;C++&#93;. Thư Viện Math.h Và Thư Viện Algorithm">
<meta property="og:type" content="website">
<meta property="og:description" content="Savefile - Tin Tức - https&#x3A;&#x002F;&#x002F;tinhocdct.xyz&#x002F;savefile&#x002F;hoat-dong-chuyen-mon&#x002F;c-thu-vien-math-h-va-thu-vien-algorithm-463.html">
<meta property="og:site_name" content="TỔ TIN HỌC TRƯỜNG THPT ĐỖ CÔNG TƯỜNG">
<meta property="og:url" content="https://tinhocdct.xyz/hoat-dong-chuyen-mon/c-thu-vien-math-h-va-thu-vien-algorithm-463.html">
<link rel="shortcut icon" href="https://tinhocdct.xyz/favicon.ico">
<link rel="canonical" href="https://tinhocdct.xyz/hoat-dong-chuyen-mon/c-thu-vien-math-h-va-thu-vien-algorithm-463.html">
<link rel="alternate" href="https://tinhocdct.xyz/rss/" title="Tin Tức" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/tin-tuc/" title="Tin Tức - TIN TỨC" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/thong-cao-bao-chi/" title="Tin Tức - THÔNG BÁO" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/ban-tin-noi-bo/" title="Tin Tức - BẢN TIN NỘI BỘ" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/tin-cong-nghe/" title="Tin Tức - CÔNG NGHỆ - KHOA HỌC" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/thu-thuat/" title="Tin Tức - THỦ THUẬT" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/tien-ich/" title="Tin Tức - TIỆN ÍCH" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/ai/" title="Tin Tức - AI" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/khoa-hoc/" title="Tin Tức - KHOA HỌC" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/hoat-dong-chuyen-mon/" title="Tin Tức - HOẠT ĐỘNG CHUYÊN MÔN" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/hoat-dong-cong-doan/" title="Tin Tức - CÔNG ĐOÀN" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/hoat-dong-doan-the/" title="Tin Tức - ĐOÀN THỂ" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/tuyen-sinh-huong-nghiep/" title="Tin Tức - TUYỂN SINH - HƯỚNG NGHIỆP" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/tuyen-sinh-2025/" title="Tin Tức - TUYỂN SINH 2025" type="application/rss+xml">
<link rel="alternate" href="https://tinhocdct.xyz/rss/lich-cong-tac-tuan/" title="Tin Tức - Lịch công tác tuần" type="application/rss+xml">
<link rel="preload" as="script" href="https://tinhocdct.xyz/assets/js/jquery/jquery.min.js">
<link rel="preload" as="script" href="https://tinhocdct.xyz/assets/js/language/vi.js">
<link rel="preload" as="script" href="https://tinhocdct.xyz/assets/js/global.js">
<link rel="preload" as="script" href="https://tinhocdct.xyz/themes/default/js/news.js">
<link rel="preload" as="script" href="https://tinhocdct.xyz/themes/default/js/main.js">
<link rel="preload" as="script" href="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1816161148536198">
<link rel="preload" as="script" href="https://tinhocdct.xyz/themes/default/js/bootstrap.min.js">
<link rel="StyleSheet" href="https://tinhocdct.xyz/assets/css/font-awesome.min.css">
<link rel="StyleSheet" href="https://tinhocdct.xyz/themes/default/css/bootstrap.non-responsive.css">
<link rel="StyleSheet" href="https://tinhocdct.xyz/themes/default/css/style.css">
<link rel="StyleSheet" href="https://tinhocdct.xyz/themes/default/css/style.non-responsive.css">
<link rel="StyleSheet" href="https://tinhocdct.xyz/themes/default/css/news.css">
<style>
	body{background: #fff;}
</style>
	</head>
	<body>
<div id="print">
	<div id="hd_print">
		<h2 class="pull-left">TỔ TIN HỌC TRƯỜNG THPT ĐỖ CÔNG TƯỜNG</h2>
		<p class="pull-right"><a title="TỔ TIN HỌC TRƯỜNG THPT ĐỖ CÔNG TƯỜNG" href="https://tinhocdct.xyz/">https://tinhocdct.xyz</a></p>
	</div>
	<div class="clear"></div>
	<hr />
	<div id="content">
		<h1>&#91;C++&#93;. Thư Viện Math.h Và Thư Viện Algorithm</h1>
		<ul class="list-inline">
			<li>Thứ hai - 31/03/2025 21:21</li>
			<li class="hidden-print txtrequired"><em class="fa fa-print">&nbsp;</em><a title="In ra" href="javascript:;" onclick="window.print()">In ra</a></li>
			<li class="hidden-print txtrequired"><em class="fa fa-power-off">&nbsp;</em><a title="Đóng cửa sổ này" href="javascript:;" onclick="window.close()">Đóng cửa sổ này</a></li>
		</ul>
		<div class="clear"></div>
		<div id="hometext">
			Trong quá trình lập trình việc sử dụng các hàm toán học là rất phổ biến, ngôn ngữ C++ cung cấp cho bạn một thư viện là math.h chứa các hàm toán học và thư viện Algorithm chứa các hàm thuật toán. Bài viết này mình sẽ cung cấp cho bạn cách sử dụng và ví dụ minh họa cho các hàm toán học và thuật toán thông dụng.
		</div>
				<div class="imghome">
			<img alt="&#91;C++&#93;. Thư Viện Math.h Và Thư Viện Algorithm" src="https://tinhocdct.xyz/uploads/news/2025_02/vi_sao_nen_hoc_cpp.png" width="460" class="img-thumbnail" />
		</div>
		<div class="clear"></div>
		<div id="bodytext" class="clearfix">
			<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(82, 87, 92);"><span style="font-family:&#039;Be Vietnam Pro&#039;, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span data-mce-style="font-size: 14pt; color: rgb(53, 152, 219);" style="font-size:14pt"><span style="box-sizing:border-box"><span style="color:rgb(53, 152, 219);"><strong style="box-sizing:border-box; font-weight:bolder">1. Các Hàm Toán Học Phổ Biến</strong></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(82, 87, 92);"><span style="font-family:&#039;Be Vietnam Pro&#039;, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Các hàm toán học trong thư viện&nbsp;<span data-mce-style="color: rgb(230, 126, 35);" style="box-sizing:border-box"><span style="color:rgb(230, 126, 35);"><strong style="box-sizing:border-box; font-weight:bolder">math.h</strong></span></span>&nbsp;đều có tham số là một số thuộc kiểu&nbsp;<span data-mce-style="color: rgb(230, 126, 35);" style="box-sizing:border-box"><span style="color:rgb(230, 126, 35);">double&nbsp;</span></span>và có kiểu trả về là&nbsp;<span data-mce-style="color: rgb(230, 126, 35);" style="box-sizing:border-box"><span style="color:rgb(230, 126, 35);">double</span></span>, bạn không cần phải nhớ hết mọi hàm mà chỉ cần nhớ cho mình một vài hàm quan trọng được sử dụng thường xuyên.&nbsp;</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
<table border="1" data-mce-style="border-collapse: collapse; width: 94.6164%; height: 383.011px;" style="-webkit-text-stroke-width:0px;border-collapse:collapse;box-sizing:border-box;color:rgb(82, 87, 92);font-family:&#039;Be Vietnam Pro&#039;,sans-serif;font-size:15px;font-style:normal;font-variant-caps:normal;font-variant-ligatures:normal;font-weight:400;height:383.011px;letter-spacing:normal;max-width:100%;orphans:2;text-align:start;text-decoration-color:initial;text-decoration-style:initial;text-decoration-thickness:initial;text-transform:none;white-space:normal;widows:2;width:823.156px;word-spacing:0px;">
	<colgroup style="box-sizing:border-box">
		<col data-mce-style="width: 6.84167%;" style="box-sizing:border-box; width:56.2422px">
		<col data-mce-style="width: 19.4708%;" style="box-sizing:border-box; width:160.086px">
		<col data-mce-style="width: 73.6811%;" style="box-sizing:border-box; width:605.828px">
	</colgroup>
	<tbody style="box-sizing:border-box">
		<tr>
			<td data-mce-style="height: 21.2784px; text-align: center;" style="height:21.2784px; text-align:center"><span style="box-sizing:border-box"><span data-mce-style="color: rgb(53, 152, 219);" style="box-sizing:border-box"><span style="color:rgb(53, 152, 219);"><strong style="box-sizing:border-box; font-weight:bolder">STT</strong></span></span></span></td>
			<td data-mce-style="height: 21.2784px; text-align: center;" style="height:21.2784px; text-align:center"><span style="box-sizing:border-box"><span data-mce-style="color: rgb(53, 152, 219);" style="box-sizing:border-box"><span style="color:rgb(53, 152, 219);"><strong style="box-sizing:border-box; font-weight:bolder">Hàm</strong></span></span></span></td>
			<td data-mce-style="height: 21.2784px; text-align: center;" style="height:21.2784px; text-align:center"><span style="box-sizing:border-box"><span data-mce-style="color: rgb(53, 152, 219);" style="box-sizing:border-box"><span style="color:rgb(53, 152, 219);"><strong style="box-sizing:border-box; font-weight:bolder">Chức năng</strong></span></span></span></td>
		</tr>
		<tr>
			<td data-mce-style="height: 21.2784px; text-align: center;" style="height:21.2784px; text-align:center"><span style="box-sizing:border-box">1</span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box"><span data-mce-style="color: rgb(230, 126, 35);" style="box-sizing:border-box"><span style="color:rgb(230, 126, 35);">pow(x, y)</span></span></span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box">Trả về x<sup style="box-sizing:border-box; position:relative; font-size:11.25px; line-height:0; vertical-align:baseline; top:-0.5em">y</sup></span></td>
		</tr>
		<tr>
			<td data-mce-style="height: 21.2784px; text-align: center;" style="height:21.2784px; text-align:center"><span style="box-sizing:border-box">2</span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box"><span data-mce-style="color: rgb(230, 126, 35);" style="box-sizing:border-box"><span style="color:rgb(230, 126, 35);">sqrt(x)</span></span></span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box">Trả về căn bậc 2 của x</span></td>
		</tr>
		<tr>
			<td data-mce-style="height: 21.2784px; text-align: center;" style="height:21.2784px; text-align:center"><span style="box-sizing:border-box">3</span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box"><span data-mce-style="color: rgb(230, 126, 35);" style="box-sizing:border-box"><span style="color:rgb(230, 126, 35);">cbrt(x)</span></span></span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box">Trả về căn bậc 3 của x</span></td>
		</tr>
		<tr>
			<td data-mce-style="height: 21.2784px; text-align: center;" style="height:21.2784px; text-align:center"><span style="box-sizing:border-box">4</span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box"><span data-mce-style="color: rgb(230, 126, 35);" style="box-sizing:border-box"><span style="color:rgb(230, 126, 35);">ceil(x)</span></span></span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box">Trả về số nguyên nhỏ nhất lớn hơn hoặc bằng x, tương đương phép làm tròn lên</span></td>
		</tr>
		<tr>
			<td data-mce-style="height: 21.2784px; text-align: center;" style="height:21.2784px; text-align:center"><span style="box-sizing:border-box">5</span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box"><span data-mce-style="color: rgb(230, 126, 35);" style="box-sizing:border-box"><span style="color:rgb(230, 126, 35);">floor(x)</span></span></span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box">Trả về số nguyên lớn nhất nhỏ hơn hoặc bằng x, tương đương phép làm tròn xuống</span></td>
		</tr>
		<tr>
			<td data-mce-style="height: 21.2784px; text-align: center;" style="height:21.2784px; text-align:center"><span style="box-sizing:border-box">6</span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box"><span data-mce-style="color: rgb(230, 126, 35);" style="box-sizing:border-box"><span style="color:rgb(230, 126, 35);">round(x)</span></span></span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box">Trả về số nguyên gần x nhất phụ thuộc phần thập phân</span></td>
		</tr>
		<tr>
			<td data-mce-style="height: 21.2784px; text-align: center;" style="height:21.2784px; text-align:center"><span style="box-sizing:border-box">7</span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box"><span data-mce-style="color: rgb(230, 126, 35);" style="box-sizing:border-box"><span style="color:rgb(230, 126, 35);">fabs(x)</span></span></span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box">Trả về trị tuyệt đối của số x</span></td>
		</tr>
		<tr>
			<td data-mce-style="height: 21.2784px; text-align: center;" style="height:21.2784px; text-align:center"><span style="box-sizing:border-box">8</span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box"><span data-mce-style="color: rgb(230, 126, 35);" style="box-sizing:border-box"><span style="color:rgb(230, 126, 35);">exp(x)</span></span></span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box">Trả về e<sup style="box-sizing:border-box; position:relative; font-size:11.25px; line-height:0; vertical-align:baseline; top:-0.5em">x</sup></span></td>
		</tr>
		<tr>
			<td data-mce-style="height: 21.2784px; text-align: center;" style="height:21.2784px; text-align:center"><span style="box-sizing:border-box">9</span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box"><span data-mce-style="color: rgb(230, 126, 35);" style="box-sizing:border-box"><span style="color:rgb(230, 126, 35);">fmod(x, y)</span></span></span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box">Trả về số dư khi chia x cho y</span></td>
		</tr>
		<tr>
			<td data-mce-style="height: 21.2784px; text-align: center;" style="height:21.2784px; text-align:center"><span style="box-sizing:border-box">10</span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box"><span data-mce-style="color: rgb(230, 126, 35);" style="box-sizing:border-box"><span style="color:rgb(230, 126, 35);">log(x)</span></span></span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box">Trả về logarit tự nhiên của x</span></td>
		</tr>
		<tr>
			<td data-mce-style="height: 21.2784px; text-align: center;" style="height:21.2784px; text-align:center"><span style="box-sizing:border-box">11</span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box"><span data-mce-style="color: rgb(230, 126, 35);" style="box-sizing:border-box"><span style="color:rgb(230, 126, 35);">log10(x)</span></span></span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box">Trả về logarit thập phân của x</span></td>
		</tr>
		<tr>
			<td data-mce-style="height: 21.2784px; text-align: center;" style="height:21.2784px; text-align:center"><span style="box-sizing:border-box">12</span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box"><span data-mce-style="color: rgb(230, 126, 35);" style="box-sizing:border-box"><span style="color:rgb(230, 126, 35);">cos(x)</span></span></span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box">Trả về giá trị hàm cos với x là radian</span></td>
		</tr>
		<tr>
			<td data-mce-style="height: 21.2784px; text-align: center;" style="height:21.2784px; text-align:center"><span style="box-sizing:border-box">13</span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box"><span data-mce-style="color: rgb(230, 126, 35);" style="box-sizing:border-box"><span style="color:rgb(230, 126, 35);">sin(x)</span></span></span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box">Trả về giá trị hàm sin với x là radian</span></td>
		</tr>
		<tr>
			<td data-mce-style="height: 21.2784px; text-align: center;" style="height:21.2784px; text-align:center"><span style="box-sizing:border-box">14</span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box"><span data-mce-style="color: rgb(230, 126, 35);" style="box-sizing:border-box"><span style="color:rgb(230, 126, 35);">tan(x)</span></span></span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box">Trả về giá trị hàm tan với x là radian</span></td>
		</tr>
		<tr>
			<td data-mce-style="height: 21.2784px; text-align: center;" style="height:21.2784px; text-align:center"><span style="box-sizing:border-box">15</span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box"><span data-mce-style="color: rgb(230, 126, 35);" style="box-sizing:border-box"><span style="color:rgb(230, 126, 35);">acos(x)</span></span></span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box">Trả về giá trị hàm arccos với x là radian</span></td>
		</tr>
		<tr>
			<td data-mce-style="height: 21.2784px; text-align: center;" style="height:21.2784px; text-align:center"><span style="box-sizing:border-box">16</span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box"><span data-mce-style="color: rgb(230, 126, 35);" style="box-sizing:border-box"><span style="color:rgb(230, 126, 35);">asin(x)</span></span></span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box">Trả về giá trị hàm arcsin với x là radian</span></td>
		</tr>
		<tr>
			<td data-mce-style="height: 21.2784px; text-align: center;" style="height:21.2784px; text-align:center"><span style="box-sizing:border-box">17</span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box"><span data-mce-style="color: rgb(230, 126, 35);" style="box-sizing:border-box"><span style="color:rgb(230, 126, 35);">atan(x)</span></span></span></td>
			<td data-mce-style="height: 21.2784px;" style="height:21.2784px"><span style="box-sizing:border-box">Trả về giá trị hàm arctan với x là radian</span></td>
		</tr>
	</tbody>
</table>
<br style="box-sizing:border-box" />
<br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(82, 87, 92);"><span style="font-family:&#039;Be Vietnam Pro&#039;, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span data-mce-style="color: rgb(53, 152, 219);" style="box-sizing:border-box"><span style="color:rgb(53, 152, 219);"><strong style="box-sizing:border-box; font-weight:bolder">Hàm pow(x,y)</strong></span></span>&nbsp;: Trả về lũy thừa x<sup style="box-sizing:border-box; position:relative; font-size:11.25px; line-height:0; vertical-align:baseline; top:-0.5em">y</sup>, lưu ý là hàm này trả về số thực double nên nếu bạn muốn tính lũy thừa với x và y nguyên thì cần lưu kết quả dưới dạng số nguyên hoặc ép kiểu khi in ra.</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(82, 87, 92);"><span style="font-family:&#039;Be Vietnam Pro&#039;, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span data-mce-style="color: rgb(230, 126, 35);" style="box-sizing:border-box"><span style="color:rgb(230, 126, 35);">Ví dụ 1:&nbsp;</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<pre>
<code class="language-cpp">#include &lt;iostream&gt;
#include &lt;math.h&gt;
#include &lt;iomanip&gt;
using namespace std;

int main(){
	int a = 2, b = 10;
    cout &lt;&lt; a &lt;&lt; &quot;^&quot; &lt;&lt; b &lt;&lt; &quot; = &quot; &lt;&lt; (int)pow(a, b) &lt;&lt; endl;
    //Tính căn bậc 5
    int n = 100;
    double res = pow(n, 1.0 / 5);
    cout &lt;&lt; fixed &lt;&lt; setprecision(3) &lt;&lt; res &lt;&lt; endl;
    return 0;
}</code></pre>
<img alt="" height="151" src="https://tinhocdct.xyz/uploads/news/2025_04/image.png" width="800" /><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(82, 87, 92);"><span style="font-family:&#039;Be Vietnam Pro&#039;, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span data-mce-style="color: rgb(53, 152, 219);" style="box-sizing:border-box"><span style="color:rgb(53, 152, 219);"><strong style="box-sizing:border-box; font-weight:bolder">Hàm sqrt(x)</strong></span></span>&nbsp;: Tính căn bậc 2 của x</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(82, 87, 92);"><span style="font-family:&#039;Be Vietnam Pro&#039;, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span data-mce-style="color: rgb(230, 126, 35);" style="box-sizing:border-box"><span style="color:rgb(230, 126, 35);">Ví dụ 2 :&nbsp;</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<pre>
<code class="language-cpp">#include &lt;iostream&gt;
#include &lt;math.h&gt;
#include &lt;iomanip&gt;
using namespace std;

int main(){
	int n = 100;
	int can = (int)sqrt(n);
	cout &lt;&lt; can &lt;&lt; endl;
	double res = sqrt(1000);
	cout &lt;&lt; fixed &lt;&lt; setprecision(2) &lt;&lt; res &lt;&lt; endl;
    return 0;
}</code></pre>
<img alt="" height="145" src="https://tinhocdct.xyz/uploads/news/2025_04/image_1.png" width="800" /><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(82, 87, 92);"><span style="font-family:&#039;Be Vietnam Pro&#039;, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span data-mce-style="color: rgb(53, 152, 219);" style="box-sizing:border-box"><span style="color:rgb(53, 152, 219);"><strong style="box-sizing:border-box; font-weight:bolder">Hàm cbrt(x)</strong></span></span>&nbsp;: Trả về căn bậc 3 của x</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(82, 87, 92);"><span style="font-family:&#039;Be Vietnam Pro&#039;, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span data-mce-style="color: rgb(230, 126, 35);" style="box-sizing:border-box"><span style="color:rgb(230, 126, 35);">Ví dụ 3 :&nbsp;</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<pre>
<code class="language-cpp">#include &lt;iostream&gt;
#include &lt;math.h&gt;
#include &lt;iomanip&gt;
using namespace std;

int main(){
	int n = 27;
	int can = (int)cbrt(n);
	cout &lt;&lt; can &lt;&lt; endl;

	double res = cbrt(100);
	cout &lt;&lt; fixed &lt;&lt; setprecision(2) &lt;&lt; res &lt;&lt; endl;
    return 0;
}</code></pre>

<pre>
<code>Output : 

3
4.64</code></pre>
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(82, 87, 92);"><span style="font-family:&#039;Be Vietnam Pro&#039;, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span data-mce-style="color: rgb(53, 152, 219);" style="box-sizing:border-box"><span style="color:rgb(53, 152, 219);"><strong style="box-sizing:border-box; font-weight:bolder">Hàm ceil(x)&nbsp;</strong></span></span>: Trả về số nguyên khi làm tròn phần thập phân của x lên, ví dụ x là 2.3 hay 2.8 thì khi sử dụng hàm ceil ta sẽ thu được số 3.</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(82, 87, 92);"><span style="font-family:&#039;Be Vietnam Pro&#039;, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span data-mce-style="color: rgb(230, 126, 35);" style="box-sizing:border-box"><span style="color:rgb(230, 126, 35);">Ví dụ 4 :&nbsp;</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<pre>
<code class="language-cpp">#include &lt;iostream&gt;
#include &lt;math.h&gt;
#include &lt;iomanip&gt;
using namespace std;

int main(){
	double a = 3.14;
	double b = 3.8;
	cout &lt;&lt; (int)ceil(a) &lt;&lt; &quot; &quot; &lt;&lt; (int)ceil(b) &lt;&lt; endl;
    return 0;
}</code></pre>
<span data-mce-style="color: rgb(230, 126, 35);" style="font-size:15px; text-align:start; text-indent:0px; -webkit-text-stroke-width:0px"><span style="box-sizing:border-box"><span style="font-family:&#039;Be Vietnam Pro&#039;, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span style="color:rgb(230, 126, 35);">Output&nbsp;</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span style="font-size:15px; text-align:start; text-indent:0px; -webkit-text-stroke-width:0px"><span style="color:rgb(82, 87, 92);"><span style="font-family:&#039;Be Vietnam Pro&#039;, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span style="display:inline !important"><span style="float:none">:</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<pre>
<code class="language-cpp">4 4</code></pre>
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(82, 87, 92);"><span style="font-family:&#039;Be Vietnam Pro&#039;, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span data-mce-style="color: rgb(53, 152, 219);" style="box-sizing:border-box"><span style="color:rgb(53, 152, 219);"><strong style="box-sizing:border-box; font-weight:bolder">Hàm floor(x)</strong>&nbsp;</span></span>: Trả về số nguyên khi làm tròn phần thập phân của x xuống, ví dụ x là 2.3 hay 2.8 thì khi sử dụng hàm ceil ta sẽ thu được số 2.</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(82, 87, 92);"><span style="font-family:&#039;Be Vietnam Pro&#039;, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span data-mce-style="color: rgb(230, 126, 35);" style="box-sizing:border-box"><span style="color:rgb(230, 126, 35);">Ví dụ 5 :</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<pre>
<code class="language-cpp">#include &lt;iostream&gt;
#include &lt;math.h&gt;
#include &lt;iomanip&gt;
using namespace std;

int main(){
	double a = 3.14;
	double b = 3.8;
	cout &lt;&lt; (int)floor(a) &lt;&lt; &quot; &quot; &lt;&lt; (int)floor(b) &lt;&lt; endl;
    return 0;
}</code></pre>

<pre>
<code>Output : 

3 3</code></pre>
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(82, 87, 92);"><span style="font-family:&#039;Be Vietnam Pro&#039;, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span data-mce-style="color: rgb(53, 152, 219);" style="box-sizing:border-box"><span style="color:rgb(53, 152, 219);"><strong style="box-sizing:border-box; font-weight:bolder">Hàm round(x)</strong></span></span>&nbsp;: Làm tròn dựa vào phần thập phân của x, nếu phần thập phân của x lớn hơn hoặc bằng 0.5 thì sẽ làm tròn lên, ngược lại sẽ làm tròn xuống</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(82, 87, 92);"><span style="font-family:&#039;Be Vietnam Pro&#039;, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span data-mce-style="color: rgb(230, 126, 35);" style="box-sizing:border-box"><span style="color:rgb(230, 126, 35);">Ví dụ 6 :&nbsp;</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<pre>
<code class="language-cpp">#include &lt;iostream&gt;
#include &lt;math.h&gt;
#include &lt;iomanip&gt;
using namespace std;

int main(){
	double a = 3.14;
	double b = 3.8;
	cout &lt;&lt; (int)round(a) &lt;&lt; &quot; &quot; &lt;&lt; (int)round(b) &lt;&lt; endl;
    return 0;
}</code></pre>

<pre>
<code>Output : 

3 4</code></pre>
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(82, 87, 92);"><span style="font-family:&#039;Be Vietnam Pro&#039;, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span data-mce-style="color: rgb(53, 152, 219);" style="box-sizing:border-box"><span style="color:rgb(53, 152, 219);"><strong style="box-sizing:border-box; font-weight:bolder">Hàm abs(x)</strong></span></span>&nbsp;: Trả về giá trị tuyệt đối của x, hàm này nằm trong thư viện stdlib.h</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(82, 87, 92);"><span style="font-family:&#039;Be Vietnam Pro&#039;, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span data-mce-style="color: rgb(230, 126, 35);" style="box-sizing:border-box"><span style="color:rgb(230, 126, 35);">Ví dụ 7 :&nbsp;</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<pre>
<code class="language-cpp">#include &lt;iostream&gt;
#include &lt;math.h&gt;
#include &lt;iomanip&gt;
using namespace std;

int main(){
	cout &lt;&lt; abs(10) &lt;&lt; &quot; &quot; &lt;&lt; abs(-100) &lt;&lt; endl;
    return 0;
}</code></pre>

<pre>
<code>Output : 

10 100</code></pre>
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(82, 87, 92);"><span style="font-family:&#039;Be Vietnam Pro&#039;, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span data-mce-style="color: rgb(53, 152, 219); font-size: 14pt;" style="font-size:14pt"><span style="box-sizing:border-box"><span style="color:rgb(53, 152, 219);"><strong style="box-sizing:border-box; font-weight:bolder">2. Thư Viện Algorithm</strong></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(82, 87, 92);"><span style="font-family:&#039;Be Vietnam Pro&#039;, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span data-mce-style="color: rgb(230, 126, 35);" style="box-sizing:border-box"><span style="color:rgb(230, 126, 35);">Algorithm&nbsp;</span></span>là thư viện chứa các hàm thuật toán phổ biến, tuy nhiên các hàm này chủ yếu dùng cho dãy mảng. Hiện tại bạn sẽ làm quen với một vài hàm cơ bản trong thư viện này trước, sau khi học phần mảng thì mình sẽ giới thiệu các hàm khác trong thư viện này.</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(82, 87, 92);"><span style="font-family:&#039;Be Vietnam Pro&#039;, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Khi sử dụng thư viện này bạn cần inlcude vào chương trình của mình.</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(82, 87, 92);"><span style="font-family:&#039;Be Vietnam Pro&#039;, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span data-mce-style="color: rgb(53, 152, 219);" style="box-sizing:border-box"><span style="color:rgb(53, 152, 219);"><strong style="box-sizing:border-box; font-weight:bolder">Hàm swap</strong></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(82, 87, 92);"><span style="font-family:&#039;Be Vietnam Pro&#039;, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Hàm này sẽ hoán đổi giá trị của 2 biến, bạn có thể tự code hoán đổi giá trị 2 biến hoặc sử dụng hàm có sẵn.</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<pre>
<code class="language-cpp">#include &lt;iostream&gt;
#include &lt;algorithm&gt;
#include &lt;iomanip&gt;
using namespace std;

int main(){
	int a = 100, b = 200;
	//Dùng hàm có sẵn
	swap(a, b);
	cout &lt;&lt; a &lt;&lt; &quot; &quot; &lt;&lt; b &lt;&lt; endl;
	//Tự code
	char x = &#039;@&#039;, y = &#039;#&#039;;
	char temp = x;
	x = y;
	y = temp;
	cout &lt;&lt; x &lt;&lt; &#039; &#039; &lt;&lt; y &lt;&lt; endl;
    return 0;
}</code></pre>

<pre>
<code>Output : 

200 100
# @</code></pre>
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(82, 87, 92);"><span style="font-family:&#039;Be Vietnam Pro&#039;, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span data-mce-style="color: rgb(53, 152, 219);" style="box-sizing:border-box"><span style="color:rgb(53, 152, 219);"><strong style="box-sizing:border-box; font-weight:bolder">Hàm min</strong></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(82, 87, 92);"><span style="font-family:&#039;Be Vietnam Pro&#039;, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Hàm min sẽ trả về giá trị nhỏ hơn trong 2 hoặc nhiều số, trong trường hợp bạn áp dụng hàm min với nhiều số thì cần thêm ngoặc nhọn {}</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<pre>
<code class="language-cpp">#include &lt;iostream&gt;
#include &lt;algorithm&gt;
#include &lt;iomanip&gt;
using namespace std;

int main(){
	int a = 100, b = 200;
	cout &lt;&lt; &quot;Min(&quot; &lt;&lt; a &lt;&lt; &quot;, &quot; &lt;&lt; b &lt;&lt; &quot;) = &quot; &lt;&lt; min(a, b) &lt;&lt; endl;
	cout &lt;&lt; &quot;Min(10, 20, 15, 4) = &quot; &lt;&lt; min({10, 20, 15, 4}) &lt;&lt; endl;
	cout &lt;&lt; &quot;Min(&#039;d&#039;, &#039;b&#039;, &#039;z&#039;,) = &quot; &lt;&lt; min({&#039;d&#039;, &#039;b&#039;, &#039;z&#039;}) &lt;&lt; endl;
    return 0;
}</code></pre>

<pre>
<code>Output : 

Min(100, 200) = 100
Min(10, 20, 15, 4) = 4
Min(&#039;d&#039;, &#039;b&#039;, &#039;z&#039;,) = b</code></pre>
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(82, 87, 92);"><span style="font-family:&#039;Be Vietnam Pro&#039;, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial"><span data-mce-style="color: rgb(53, 152, 219);" style="box-sizing:border-box"><span style="color:rgb(53, 152, 219);"><strong style="box-sizing:border-box; font-weight:bolder">Hàm max</strong></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br  />
<span style="font-size:15px"><span style="box-sizing:border-box"><span style="color:rgb(82, 87, 92);"><span style="font-family:&#039;Be Vietnam Pro&#039;, sans-serif"><span style="font-style:normal"><span style="font-variant-ligatures:normal"><span style="font-variant-caps:normal"><span style="font-weight:400"><span style="letter-spacing:normal"><span style="orphans:2"><span style="text-transform:none"><span style="widows:2"><span style="word-spacing:0px"><span style="white-space:normal"><span style="text-decoration-thickness:initial"><span style="text-decoration-style:initial"><span style="text-decoration-color:initial">Hàm max sẽ trả về giá trị lớn hơn trong 2 hoặc nhiều số, trong trường hợp bạn áp dụng hàm max với nhiều số thì cần thêm ngoặc nhọn {}</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

<pre>
<code class="language-cpp">#include &lt;iostream&gt;
#include &lt;algorithm&gt;
#include &lt;iomanip&gt;
using namespace std;

int main(){
	int a = 100, b = 200;
	cout &lt;&lt; &quot;Max(&quot; &lt;&lt; a &lt;&lt; &quot;, &quot; &lt;&lt; b &lt;&lt; &quot;) = &quot; &lt;&lt; max(a, b) &lt;&lt; endl;
	cout &lt;&lt; &quot;Max(10, 20, 15, 4) = &quot; &lt;&lt; max({10, 20, 15, 4}) &lt;&lt; endl;
	cout &lt;&lt; &quot;Max(&#039;d&#039;, &#039;b&#039;, &#039;z&#039;,) = &quot; &lt;&lt; max({&#039;d&#039;, &#039;b&#039;, &#039;z&#039;}) &lt;&lt; endl;
    return 0;
}</code></pre>

<pre>
<code>Output : 

Max(100, 200) = 200
Max(10, 20, 15, 4) = 20
Max(&#039;d&#039;, &#039;b&#039;, &#039;z&#039;,) = z</code></pre>
&nbsp;

<div><a href="https://tinhocdct.xyz/hoat-dong-chuyen-mon/c-toan-tu-operator-462.html" target="_blank"><img alt="bai truoc" height="35" src="https://tinhocdct.xyz/uploads/news/2025_02/bai-truoc.png" width="120" /></a><img alt="bai tiep" height="35" src="https://tinhocdct.xyz/uploads/news/2025_02/bai-tiep.png" style="float:right" width="120" /></div>
<br  />
		</div>
				<div id="author">
						<p>
				<strong>Tác giả bài viết:</strong>
				Thanh Sơn
			</p>
						<p>
				<strong>Nguồn tin:</strong>
				blog.28tech.com.vn
			</p>
		</div>
	</div>
	<div id="footer" class="clearfix">
		<div id="url">
			<strong>URL của bản tin này: </strong><a href="https://tinhocdct.xyz/hoat-dong-chuyen-mon/c-thu-vien-math-h-va-thu-vien-algorithm-463.html" title="&#91;C++&#93;. Thư Viện Math.h Và Thư Viện Algorithm">https://tinhocdct.xyz/hoat-dong-chuyen-mon/c-thu-vien-math-h-va-thu-vien-algorithm-463.html</a>

		</div>
		<div class="clear"></div>
		<div class="copyright">
			&copy; TỔ TIN HỌC TRƯỜNG THPT ĐỖ CÔNG TƯỜNG
		</div>
		<div id="contact">
			<a href="mailto:webmaster@tinhocdct.xyz">webmaster@tinhocdct.xyz</a>
		</div>
	</div>
</div>
        <div id="timeoutsess" class="chromeframe">
            Bạn đã không sử dụng Site, <a onclick="timeoutsesscancel();" href="https://tinhocdct.xyz/#">Bấm vào đây để duy trì trạng thái đăng nhập</a>. Thời gian chờ: <span id="secField"> 60 </span> giây
        </div>
        <div id="openidResult" class="nv-alert" style="display:none"></div>
        <div id="openidBt" data-result="" data-redirect=""></div>
<script src="https://tinhocdct.xyz/assets/js/jquery/jquery.min.js"></script>
<script>var nv_base_siteurl="/",nv_lang_data="vi",nv_lang_interface="vi",nv_name_variable="nv",nv_fc_variable="op",nv_lang_variable="language",nv_module_name="news",nv_func_name="savefile",nv_is_user=0, nv_my_ofs=-4,nv_my_abbr="EDT",nv_cookie_prefix="nv4",nv_check_pass_mstime=1738000,nv_area_admin=0,nv_safemode=0,theme_responsive=0,nv_is_recaptcha=0;</script>
<script src="https://tinhocdct.xyz/assets/js/language/vi.js"></script>
<script src="https://tinhocdct.xyz/assets/js/global.js"></script>
<script src="https://tinhocdct.xyz/themes/default/js/news.js"></script>
<script src="https://tinhocdct.xyz/themes/default/js/main.js"></script>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1816161148536198"
     crossorigin="anonymous"></script>
<script src="https://tinhocdct.xyz/themes/default/js/bootstrap.min.js"></script>
</body>
</html>