<!DOCTYPE html>
    <html lang="vi" xmlns="http://www.w3.org/1999/xhtml" prefix="og: http://ogp.me/ns#">
    <head>
<title>Chuyên đề xử lý số nguyên lớn trong Pascal</title>
<meta name="description" content="Chuyên đề xử lý số nguyên lớn trong Pascal - Savefile - Tin Tức - https&#x3A;&#x002F;&#x002F;thptphuquoc.edu.vn&#x002F;savefile&#x002F;cac-cau-lac-bo&#x002F;chuyen-de-xu-ly-so-nguyen-lon-trong-pasxal-50.html">
<meta name="author" content="Trường THPT Phú Quốc">
<meta name="copyright" content="Trường THPT Phú Quốc [webmaster@thptphuquoc.edu.vn]">
<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.3">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta property="og:title" content="Chuyên đề xử lý số nguyên lớn trong Pascal">
<meta property="og:type" content="website">
<meta property="og:description" content="Savefile - Tin Tức - https&#x3A;&#x002F;&#x002F;thptphuquoc.edu.vn&#x002F;savefile&#x002F;cac-cau-lac-bo&#x002F;chuyen-de-xu-ly-so-nguyen-lon-trong-pasxal-50.html">
<meta property="og:site_name" content="Trường THPT Phú Quốc">
<meta property="og:url" content="https://thptphuquoc.edu.vn/cac-cau-lac-bo/chuyen-de-xu-ly-so-nguyen-lon-trong-pasxal-50.html">
<link rel="shortcut icon" href="https://thptphuquoc.edu.vn/favicon.ico">
<link rel="canonical" href="https://thptphuquoc.edu.vn/cac-cau-lac-bo/chuyen-de-xu-ly-so-nguyen-lon-trong-pasxal-50.html">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/" title="Tin Tức" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/tin-tuc/" title="Tin Tức - TIN TỨC" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/thong-bao/" title="Tin Tức - THÔNG BÁO" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/tuyen-sinh-lop-10/" title="Tin Tức - TUYỂN SINH LỚP 10" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/cac-to-chuc/" title="Tin Tức - CÁC TỔ CHỨC" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/dang-bo/" title="Tin Tức - Đảng bộ" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/cac-chi-bo/" title="Tin Tức - Các chi bộ" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/ban-giam-hieu/" title="Tin Tức - Ban giám hiệu" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/cong-doan/" title="Tin Tức - Công đoàn" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/to-chuyen-mon-83/" title="Tin Tức - Tổ chuyên môn" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/doan-thanh-nien/" title="Tin Tức - Đoàn thanh niên" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/hoi-khuyen-hoc/" title="Tin Tức - Hội khuyến học" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/hoi-phu-huynh-hs/" title="Tin Tức - Hội cha mẹ học sinh" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/noo/" title="Tin Tức - NỘI QUY, QUY CHẾ" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/tkb/" title="Tin Tức - THỜI KHÓA BIỂU" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/tuyen-dung/" title="Tin Tức - CÁC KẾ HOẠCH" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/dien-hinh-tien-tien/" title="Tin Tức - ĐIỂN HÌNH TIÊN TIẾN" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/tai-nguyen/" title="Tin Tức - TÀI NGUYÊN" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/tai-lieu/" title="Tin Tức - Tài liệu" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/de-kiem-tra/" title="Tin Tức - Đề thi, đề kiểm tra" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/de-thi-hsg/" title="Tin Tức - Đề thi học sinh giỏi" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/sang-kien-giai-phap/" title="Tin Tức - Sáng kiến, giải pháp" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/phuong-phap-hoc-tap/" title="Tin Tức - Phương pháp học tập" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/cac-van-ban/" title="Tin Tức - Các văn bản" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/cac-phan-mem/" title="Tin Tức - Các phần mềm" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/trai-nghiem-sang-tao/" title="Tin Tức - TRẢI NGHIỆM-SÁNG TẠO" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/bai-viet-26/" title="Tin Tức - BÀI VIẾT" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/cac-cau-lac-bo/" title="Tin Tức - ĐOÀN, HỘI" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/goc-doan-truong/" title="Tin Tức - Đoàn trường" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/goc-cong-doan/" title="Tin Tức - Công đoàn" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/clb-toan-hoc/" title="Tin Tức - Câu lạc bộ Toán học" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/clb-tieng-anh/" title="Tin Tức - Câu lạc bộ Tiếng anh" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/http-123cunghoctin-com/" title="Tin Tức - Câu lạc bộ Tin học" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/clb-van-hoc/" title="Tin Tức - Câu lạc bộ Văn học" type="application/rss+xml">
<link rel="alternate" href="https://thptphuquoc.edu.vn/rss/thu-vien/" title="Tin Tức - THƯ VIỆN" type="application/rss+xml">
<link rel="preload" as="script" href="https://thptphuquoc.edu.vn/assets/js/jquery/jquery.min.js">
<link rel="preload" as="script" href="https://thptphuquoc.edu.vn/assets/js/language/vi.js">
<link rel="preload" as="script" href="https://thptphuquoc.edu.vn/assets/js/global.js">
<link rel="preload" as="script" href="https://thptphuquoc.edu.vn/themes/default/js/news.js">
<link rel="preload" as="script" href="https://thptphuquoc.edu.vn/themes/default/js/main.js">
<link rel="preload" as="script" href="https://thptphuquoc.edu.vn/themes/default/js/custom.js">
<link rel="preload" as="script" href="https://thptphuquoc.edu.vn/themes/default/js/bootstrap.min.js">
<link rel="stylesheet" href="https://thptphuquoc.edu.vn/assets/css/font-awesome.min.css">
<link rel="stylesheet" href="https://thptphuquoc.edu.vn/themes/default/css/bootstrap.min.css">
<link rel="stylesheet" href="https://thptphuquoc.edu.vn/themes/default/css/style.css">
<link rel="stylesheet" href="https://thptphuquoc.edu.vn/themes/default/css/style.responsive.css">
<link rel="StyleSheet" href="https://thptphuquoc.edu.vn/themes/default/css/news.css">
<link rel="stylesheet" href="https://thptphuquoc.edu.vn/themes/default/css/custom.css">
<link rel="stylesheet" href="https://thptphuquoc.edu.vn/assets/css/default.vi.0.css">
<style>
	body{background: #fff;}
</style>
    </head>
    <body>
<div id="print">
	<div id="hd_print">
		<h2 class="pull-left">Trường THPT Phú Quốc</h2>
		<p class="pull-right"><a title="Trường THPT Phú Quốc" href="https://thptphuquoc.edu.vn/">https://thptphuquoc.edu.vn</a></p>
	</div>
	<div class="clear"></div>
	<hr />
	<div id="content">
		<h1>Chuyên đề xử lý số nguyên lớn trong Pascal</h1>
		<ul class="list-inline">
			<li>Thứ tư - 07/02/2018 04:27</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">
			Tài liệu sưu tầm
		</div>
		<div id="bodytext" class="clearfix">
			<span style="font-size:14pt"><span style="line-height:150%"><span style="tab-stops:9.0pt 36.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"><a name="_Toc451156707"></a><a name="_Toc358416062"><b><span style="font-size:16.0pt"><span style="line-height:150%">I.&nbsp; ĐẶT VẤN ĐỀ</span></span></b></a></span></span></span></span><br  />
<br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">Tin học là môn học khoa học có tính thực tiễn cao, luôn đòi hỏi người học không chỉ có lĩnh hội những kiến thức trên lớp mà còn cần phải có những hiểu biết thực tế rộng gắn liền với môn Tin học thì việc học mới thực sự có hiệu quả và dễ nhớ kiến thức. Trong thực tế hiện nay, sự hiểu biết thực tế của các em về kiến thức thực tế môn Tin học lại rất hạn chế. Vì vậy khi học, các em sẽ trở nên bị động, không vận dụng được kiến thức đã học vào thưc tiễn. Do đó, khi ghi nhớ kiến thực học sinh dễ quên. Cũng vì lẽ đó, &nbsp;môn Tin học THPT luôn được học sinh xem là một môn học khó và thiếu hứng thú học tập.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="tab-stops:49.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Lập trình là vấn đề tương đối mới đối với học sinh THPT. Trong quá trình lập trình nếu học sinh không nắm vững các kiến thức để viết chương trình thì thường dẫn đến các sai sót dẫn tới chương trình không đạt được kết quả như mong muốn.</span></span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;Khi làm việc với số nguyên lớn có thể làm cho học sinh hay mắc phải những nhó khăn thư thế. Chính vì vậy, tôi mạnh dạn viết sáng kiến <b>“ỨNG DỤNG KIỂU XÂU TRONG PHÉP TOÁN &nbsp;SỐ NGUYÊN LỚN ”</b>. Hy vọng rằng những kinh nghiệm này của tôi có thể góp phần giúp các em học sinh hiểu bài hơn và có hứng thú hơn với môn Tin học.</span></span></span><br  />
<br  />
<br clear="all" style="page-break-before:always" />
<span style="font-size:14pt"><span style="font-family:&#039;Times New Roman&#039;,serif"><a name="_Toc451156708"><b><span style="font-size:16.0pt">II</span></b></a><span style="font-size:16.0pt">. <b>GIẢI QUYẾT VẤN ĐỀ</b></span></span></span><br  />
<br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif"><a name="_Toc451156709"></a><a name="_Toc358416064"><b>1. Cơ sở lý luận của vấn đề:</b></a></span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="tab-stops:list 0mm"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Môn Tin học không phải là môn khoa học lý thuyết thuần túy vì vậy học sinh không thể nhớ nếu như không hiểu bài. Việc giáo viên bắt học sinh ghi nhớ thụ động từng nội dung trong sách giáo khoa là một điều cực khó, cho dù học sinh có cố gắng ghi nhớ thì vẫn bị lẫn lộn. Hơn nữa, khi gặp các bài toán phải sử dụng kiểu dữ liệu lớn nhiều em lúng lúng. Việc giải các bài toán với kiểu dữ liệu lớn thực sự cần thiết cho các em khi làm các bài toán lập trình trong chương trình Tin học phổ thông nói riêng và việc giải quyết các bài toán thực tế nói chung.</span></span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif"><a name="_Toc451156710"></a><a name="_Toc358416065"><b>2. Thực trạng của vấn đề:</b></a></span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="tab-stops:list 0mm"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Trong chương trình sách giáo khoa Tin học 11 có giới thiệu các kiểu dữ liệu số nguyên. Kiểu dữ liệu nguyên lớn nhất mà các em được biết đó là kiểu số nguyên lớn (longint) có phạm vi <code style="font-family:&#039;Courier New&#039;; color:rgb(0, 96, 0);"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,&#039;serif&#039;">-2147483648 .. 2147483647. &nbsp;Nhiều em học sinh cho rằng, ngôn ngữ lập trình Pascal chỉ có thể giải được các bài toán có phép tính trong khoảng số nguyên lớn mà các em được biết. Tin học là môn trong những môn học được ứng dụng nhiều trong thực tế. Trong thực tế cần phải giải quyết các bài toán, phép toán với các số rất lớn. Việc các em có thể giải được các bài toán với số nguyên lớn thực sự cần thiết. Thông qua đó, các em có thể giải các bài toán trong thực tế, góp phần đưa kiến thức học lập trình tin học vào đời sống.</span></span></code></span></span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif"><a name="_Toc451156711"></a><a name="_Toc358416066"><b>3. Giải quyết vấn đề và tổ chức thực hiện</b></a></span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif"><a name="_Toc451156712"></a><a name="_Toc358416067"><b>3.1 &nbsp;Giải quyết vấn đề.</b></a></span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Phương pháp</b>: - Các số lớn được lưu dưới dạng xâu. Độ dài xâu tối đa là 255 kí tự. Vì vậy, xâu có thể lưu trữ được số có tối đa là 255 chữ số.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; - Sử dụng các phép tính toán trên xâu để tính kết quả. Trong khi tính toán cần sử dụng hiệu quả các thủ tục chuyển đổi kí tự kiểu xâu thành số và ngược lại từ số thành xâu.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; - Hiện thị kết quả dạng xâu (hoặc mảng).</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif"><b>&nbsp;&nbsp; <a name="_Toc451156713">3.2&nbsp; Tổ chức thực hiện:</a> </b></span></span></span>
<h3 style="margin:12pt 0mm 3pt"><span style="font-size:13pt"><span style="font-family:Cambria,serif">&nbsp;&nbsp;&nbsp;&nbsp; <a name="_Toc451156714"><u><span style="font-weight:normal">Bài toán1</span></u></a> &nbsp;: <i><span style="font-weight:normal">“Hãy tính tổng của hai số tự nhiên lớn”.</span></i> </span></span></h3>
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">Bài toán này có nhiều cách giải sau đây là lời giải tự nhiên nhất nhưng cũng rất hiệu quả và dễ hiểu như sau:</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp; &nbsp;* <b>Ý tưởng</b>:</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; - Hai số được lưu dưới dạng xâu. Các số có thể đọc ra từ tệp lưu vào biến kiểu xâu hoặc các số có thể được nhập từ màn hình lưu vào biến kiểu xâu.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">- So sánh độ dài hai xâu, tìm độ dài xâu lớn nhất.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">- Thêm kí tự &#039;0&#039; vào xâu có độ dài ngắn hơn để hai xâu bằng nhau.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">- Thực hiện phép cộng hai xâu có độ dài bằng nhau. Thực hiện phép cộng từ cuối lên đầu (tương tự như cộng ở số được thực hiện từ hàng đơn vị). Trong quá trình cộng có sử dụng thủ tục trung gian chuyển đổi từ xâu sang số và ngược lại (lưu ý phần nhớ của phép cộng).</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">- Kết quả đưa trực tiếp vào xâu.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">- Hiển thị kết quả dạng xâu.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif"><b>&nbsp;&nbsp; * Các bước thực hiện:</b></span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&nbsp; Hai số được nhập từ bàn phím và lưu vào hai biến kiểu xâu st1 và st2.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; -&nbsp; So sánh hai xâu st1 và st2. Thêm kí tự ‘0’ vào xâu ngắn hơn để hai xâu có độ dài bằng nhau.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - Thực hiện phép cộng hai xâu có có độ dài bằng nhau, cộng từ cuối lên đầu (tương tự như cộng ở số được thực hiện từ hàng đơn vị). Các kí tự trong xâu lần lượt chuyển thành số (sử dụng thủ tục chuyển đổi) rồi thực hiện phép cộng. Kết quả cộng các số được chuyển ngược lại thành xâu (h1).</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nho:=0; h:=&#039;&#039;;</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;For i:=Max downto 1 do</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Begin</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;val(s1&#91;i&#93;,a,code);</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; val(s2&#91;i&#93;,b,code);</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tam:=a+b+nho;</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if tam&gt;=10 Then nho:=1&nbsp; Else nho:=0;</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str(tam Mod 10,h1);</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; h:=h1+h;</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End;</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">- Sử dụng xâu kết quả (h) lưu trữ kết quả các phép cộng (lưu ý phần nhớ)</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif"><b><u>Chương trình:</u></b></span></span></span>

<table class="Table" style="border-collapse:collapse; border:solid windowtext 1.0pt">
	<tbody>
		<tr>
			<td style="border:solid windowtext 1.0pt; width:481.05pt; padding:0mm 5.4pt 0mm 5.4pt" valign="top" width="641"><span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">Program so_lon;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;var</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp; st,st1,st2:string;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;Function Cong(s1,s2:String):String;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">Var</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp; L1,L2,Max,i,tam,a,b,code,nho:Integer;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp; h,h1:String;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">Begin</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;L1:=length(s1);</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;L2:=length(s2);</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">if L1&gt;L2 Then Max:=L1 Else Max:=L2;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;For i:=L1+1 to Max do s1:=&#039;0&#039;+s1;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">For i:=L2+1 to Max do s2:=&#039;0&#039;+s2;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">nho:=0; h:=&#039;&#039;;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">For i:=Max downto 1 do</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp; Begin</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; val(s1&#91;i&#93;,a,code);</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; val(s2&#91;i&#93;,b,code);</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tam:=a+b+nho;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">if tam&gt;=10 Then nho:=1&nbsp; Else nho:=0;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp; str(tam Mod 10,h1);</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">h:=h1+h; End;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">if nho=1 Then h:=&#039;1&#039;+h;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">cong:=h;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;End;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;Begin</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp; write(&#039;nhap so thu nhat&#039;); readln(st1);</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp; write(&#039;nhap so thu hai&#039;); readln(st2);</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp; writeln(&#039;ket qua la&#039;, cong(st1,st2));</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp; readln;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;End. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></span></td>
		</tr>
	</tbody>
</table>
<br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif"><b><u>Nhận xét</u></b><u>:</u></span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;- Chương trình trên thực hiện việc cộng hai số được nhập từ bàn phím.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">- Trong chương trình có sử dụng chương trình con <i>Cong(s1,s2:String): String</i> để tính kết quả phép cộng hai xâu s1, s2.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">- &nbsp;Kết quả phép cộng được hiện lên trên màn hình.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">- Ta có thể thay đổi chương trình bằng cách sử dụng tệp để đọc dữ liệu vào và ghi kết quả ra.</span></span></span><br  />
<br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif"><b>&nbsp; *&nbsp; Bây giờ chúng ta tìm hiểu giải thuật kinh điển cho dạng toán này như sau:</b></span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - Giả sử hai số được cho bởi chuổi s1,s2</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - Thêm kí tự ‘0’ vào bên trái số có chiều dài ngắn để 2 chuổi s1,s2 có chiều dài bằng nhau và giả sử chiều dài lúc đó là Max.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - Kết quả được đưa vào mảng C.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - Tính c&#91;i&#93;=a&#91;i&#93;+b&#91;i&#93; với mọi i(i=1..Max)</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp; Ví dụ: a=986 b=927</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thì c&#91;1&#93;=18;&nbsp; c&#91;2&#93;=10;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; c&#91;3&#93;=13;</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - Để C là mảng số kết quả cần biến đổi một chút nữa như sau:</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">- Duyệt mảng C từ phải qua trái, mỗi c&#91;i&#93; chỉ giữ lại phần dư còn phần nguyên thì cộng thêm cho phần tử c&#91;i-1&#93; như sau:</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp; For i:=Max downto 1 do Begin</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;c&#91;i-1&#93;:=c&#91;i-1&#93; + c&#91;i&#93; Div 10;</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c&#91;i&#93;:=c&#91;i&#93; Mod 10;</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End;</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp; <b><u>Chương trình kết quả đưa vào mảng.</u></b></span></span></span>

<table class="Table" style="border-collapse:collapse; border:solid windowtext 1.0pt">
	<tbody>
		<tr>
			<td style="border:solid windowtext 1.0pt; width:481.05pt; padding:0mm 5.4pt 0mm 5.4pt" valign="top" width="641"><span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;USES CRT;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;Procedure cong;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;Var&nbsp;&nbsp;&nbsp; s1,s2:String; a,b,i,L1,L2,code:word; max:longint;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c:Array&#91;0..255&#93; of &nbsp;byte;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;Begin</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp; Write(&#039;Nhap so thu nhat&#039;); Readln(s1);</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp; Write(&#039;Nhap so thu hai&#039;);&nbsp; Readln(s2);</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; L1:=length(s1); L2:=length(s2);</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if L1&gt;L2 Then Max:=L1 Else Max:=L2;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For i:=L2+1 to Max do s2:=&#039;0&#039;+s2;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For i:=L1+1 to Max do&nbsp; s1:=&#039;0&#039;+s1;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For i:=0 to 255 do C&#91;i&#93;:=0;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp; For i:=0 to Max do</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Begin</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; val(s1&#91;i&#93;,A,code);</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; val(s2&#91;i&#93;,B,code);</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c&#91;i&#93;:=a+b;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp; For i:=Max downto 1 do</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp; Begin</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c&#91;i-1&#93;:=c&#91;i-1&#93; + c&#91;i&#93; Div 10;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c&#91;i&#93;:=c&#91;i&#93; Mod 10;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;For i:=0 to Max do Write(c&#91;i&#93;);</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;End;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">BEGIN</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;cong;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;readln;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">END.</span></span></span></td>
		</tr>
	</tbody>
</table>
<br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif"><b><u>Nhận xét</u>: </b></span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - </b>Chương trình trên thực hiện việc cộng hai số nguyên lớn được nhập từ bàn phím. Kết quả của phép cộng được hiển thị trên màn hình.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;- Ngoài ra ta có thể&nbsp; sử dụng tệp để đọc các số nguyên lớn vào và ghi kết quả ra</span></span></span><br  />
&nbsp;
<h3 style="margin:12pt 0mm 3pt"><span style="font-size:13pt"><span style="font-family:Cambria,serif"><a name="_Toc451156715"><u><span style="font-weight:normal">Bài toán 2</span></u></a><span style="font-weight:normal">: <i>Chương trình trừ 2 số tự nhiên lớn</i></span></span></span></h3>
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif"><b>* Ý tưởng</b>:</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">- Hai số được lưu dưới dạng xâu. Các số có thể đọc ra từ tệp lưu vào biến kiểu xâu hoặc các số có thể được nhập từ màn hình lưu vào biến kiểu xâu.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">- So sánh độ dài hai xâu, tìm độ dài xâu lớn nhất</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">- Thêm kí tự &#039;0&#039; vào xâu có độ dài ngắn hơn để hai xâu bằng nhau.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">- So sánh hai xâu có độ dài bằng nhau. &nbsp;&nbsp;&nbsp;&nbsp;</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;+ Nếu xâu lưu số bị trừ lớn hơn xâu lưu số trừ. Thực hiện phép trừ hai xâu từ cuối lên đầu (tương tự như phép trừ trong toán học). Sử dụng thủ tục chuyển đổi xâu thành số trong quá trình tính toán.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;+ Nếu xâu lưu số bị trừ bé hơn xâu lưu số trừ thực hiện đặt dấu trừ (-) vào phần đầu kết quả, đồng thời thực hiện hoán đổi hai xâu cho nhau và thực hiện phép trừ tương tự như ở trên.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif"><b>* Các bước thực hiện:</b></span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif"><b>- </b>Nhập hai số từ bàn phím lưu vào hai biến xâu st1, st2.<b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </b></span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - </b>So sánh hai xâu st1 và st2. Thêm kí tự ‘0’ vào xâu ngắn hơn để hai xâu có độ dài bằng nhau.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif"><b>-</b> So sánh hai xâu st1, st2 độ dài bằng nhau.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">+ Nếu xâu lưu số bị trừ lớn hơn xâu lưu số trừ. Thực hiện phép trừ hai xâu từ cuối lên đầu (tương tự như phép trừ trong toán học). Sử dụng thủ tục chuyển đổi xâu thành số trong quá trình tính toán.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">+ Nếu xâu lưu số bị trừ bé hơn xâu lưu số trừ thực hiện đặt dấu trừ (-) vào phần đầu kết quả, đồng thời thực hiện hoán đổi hai xâu cho nhau và thực hiện phép trừ tương tự như ở trên.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">- Phép trừ được thực hiện như sau:</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </b>&nbsp;Các kí tự sâu St1 được chuyển thành số và lưu vào mảng h1.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Các kí tự sâu St2 được chuyển thành số và lưu vào mảng h2.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;Thực hiện phép trừ hai mảng h1 và h2 (lưu ý trương hợp số bị trừ bé hơn số trừ)</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Nếu h1&#91;i&#93;&lt;h2&#91;i&#93; thì &nbsp; c&#91;i&#93;:=h1&#91;i&#93;+10-h2&#91;i&#93;; và &nbsp;&nbsp;h2&#91;i-1&#93;:=h2&#91;i-1&#93;+1; ngược lại nếu h1&#91;i&#93;&gt;=h2&#91;i&#93; thì c&#91;i&#93;:=h1&#91;i&#93;-h2&#91;i&#93;;</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;- Mảng C thu được chính là kết quả.</span></span></span><br  />
<br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif"><b><u>Chương trình:</u></b></span></span></span>

<table class="Table" style="border-collapse:collapse; border:solid windowtext 1.0pt">
	<tbody>
		<tr>
			<td style="border:solid windowtext 1.0pt; width:481.05pt; padding:0mm 5.4pt 0mm 5.4pt" valign="top" width="641"><span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">program tru_so_lon;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;var st1,st2:string;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;Procedure tru(s1,s2:string);</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp; Var&nbsp;&nbsp; s:String;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; h1,h2:Array&#91;1..255&#93; of&nbsp; byte;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C:Array&#91;1..255&#93; of&nbsp; byte;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dau:Char;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp; code,l1,l2,Max,i:word;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;Begin</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp; L1:=length(s1);</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;L2:=length(s2);</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">if L1&gt;L2 Then Max:=L1 Else Max:=L2;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;For i:=L2+1 to Max do s2:=&#039;0&#039;+s2;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;For i:=L1+1 to Max do s1:=&#039;0&#039;+s1;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">dau:=&#039; &#039;;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">IF s2&gt;s1 Then</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp; Begin</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp; dau:=&#039;-&#039;;&nbsp; s:=s2;&nbsp; s2:=s1;&nbsp; s1:=s;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For i:=1 to 255 do C&#91;i&#93;:=0;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;For i:=1 to Max do</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">Begin</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;val(s1&#91;i&#93;,h1&#91;i&#93;,code);</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;val(s2&#91;i&#93;,h2&#91;i&#93;,code);</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;End;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;For i:=Max downto 1 do</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IF h1&#91;i&#93;&lt;h2&#91;i&#93; Then</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Begin</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c&#91;i&#93;:=h1&#91;i&#93;+10-h2&#91;i&#93;;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; h2&#91;i-1&#93;:=h2&#91;i-1&#93;+1;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End&nbsp; Else</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c&#91;i&#93;:=h1&#91;i&#93;-h2&#91;i&#93;;</span></span></span><br  />
			<br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">Write(dau);</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">For i:=1 to Max do Write(c&#91;i&#93;);</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">End;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">Begin</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">write(&#039;nhap so thu nhat&#039;); readln(st1);</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp; write(&#039;nhap so thu nhat&#039;); readln(st2);</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp; writeln(&#039;ket qua la&#039;);</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp; tru(st1,st2);</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">Readln;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">End.</span></span></span></td>
		</tr>
	</tbody>
</table>
<br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif"><b><u>Nhận xét</u>: </b></span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif"><b>- </b>Chương trình trên thực hiện phép trừ hai số lớn được nhập từ bàn phím. Hiệu của hai số được hiển thị trên màn hình.</span></span></span>

<ul>
	<li style="list-style-type:none">
	<ul>
		<li style="text-align:justify; margin:0mm 0mm 0.0001pt"><span style="font-size:14pt"><span style="line-height:150%"><span style="tab-stops:list 0mm"><span style="font-family:&#039;Times New Roman&#039;,serif">Kết quả phép trừ được lưu vào một mảng. Để hiện thị kết quả, ta chỉ cần hiển thị lần lượt các phần tử trong mảng. Khi hiện thỉ cần chú ý tới phần dấu của phép trừ (nếu số bị trù bé hơn số trừ ghi vào kết quả dấu )</span></span></span></span></li>
	</ul>
	</li>
</ul>
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">- Tương tự như các bài ở trên, ta có thể thay đối cách vào ra dữ liệu bằng cách sử dụng tệp để đọc dữ liệu vào và ghi kết quả ra.</span></span></span><br  />
&nbsp;
<h3 style="margin:12pt 0mm 3pt"><span style="font-size:13pt"><span style="font-family:Cambria,serif"><a name="_Toc451156716"><u><span style="font-weight:normal">Bài toán 3</span></u></a><span style="font-weight:normal">: <i>Chương trình nhân 2 số tự nhiên lớn</i>.</span></span></span></h3>
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif"><b>&nbsp;* Ý tưởng: </b></span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">- Hai số được lưu dưới dạng xâu. Các số có thể đọc ra từ tệp lưu vào biến kiểu xâu hoặc các số có thể được nhập từ màn hình lưu vào biến kiểu xâu.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;- Thực hiện phép nhân lần lượt các kí tự (đã dùng thủ tục chuyển thành số) trong hai xâu.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">- Kết quả đưa vào mảng.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">- Xử lý mảng kết quả ta thu được kết quả phép nhân.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif"><b>* Các bước thực hiện:</b></span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; - Nhập hai số lưu ở dang hai biến xâu s1, s2.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - Sử dụng mảng C lưu kết quả phép nhân hai xâu s1, s2 (các kí tự trong xâu được chuyển đối thành số khi tính toán).</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - Ta có:&nbsp; L1:=length(s1); L2:=length(s2);</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For i:=1 to L1 do</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For j:=1 to L2 do</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Begin</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;val(s1&#91;i&#93;,A,code);</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;val(s2&#91;j&#93;,B,code);</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c&#91;i+j&#93;:=c&#91;i+j&#93;+a*b;</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;End;</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">- Xử lý mảng kết quả:</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For i:=L1+L2 downto 3 do</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Begin</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c&#91;i-1&#93;:=c&#91;i-1&#93; + c&#91;i&#93; Div 10;</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c&#91;i&#93;:=c&#91;i&#93; Mod 10;</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End;</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;<b><u>Chương trình:</u></b></span></span></span>

<table class="Table" style="border-collapse:collapse; border:solid windowtext 1.0pt">
	<tbody>
		<tr>
			<td style="border:solid windowtext 1.0pt; width:481.05pt; padding:0mm 5.4pt 0mm 5.4pt" valign="top" width="641"><span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp; Program nhan_hai_so;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp; Var&nbsp;&nbsp;&nbsp; s1,s2:String;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp; C&nbsp; :Array&#91;0..10000&#93; of byte;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;Procedure nhan;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp; Var&nbsp;&nbsp; a,b,i,j,L1,L2,code:word;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;Begin</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Write(&#039; Nhap so thu nhat&#039;);&nbsp; Readln(s1);</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Write(&#039; Nhap so thư hai&#039;);&nbsp;&nbsp; Readln(s2);</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; L1:=length(s1); L2:=length(s2);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For i:=1 to l1+l2 do C&#91;i&#93;:=0;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;For i:=1 to L1 do For j:=1 to L2 do</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;Begin</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">val(s1&#91;i&#93;,A,code);</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;val(s2&#91;j&#93;,B,code);</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;c&#91;i+j&#93;:=c&#91;i+j&#93;+a*b;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">End;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">For i:=L1+L2 downto 3 do</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;Begin</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;c&#91;i-1&#93;:=c&#91;i-1&#93; + c&#91;i&#93; Div 10;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;c&#91;i&#93;:=c&#91;i&#93; Mod 10;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;End;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">Write(&#039;Tich la : &#039;);&nbsp;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp; For i:=2 to L1+L2 do Write(c&#91;i&#93;);</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">End;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">Begin</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">Nhan;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">Readln;</span></span></span><br  />
			<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">End.</span></span></span></td>
		</tr>
	</tbody>
</table>
<br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif"><b><u>Nhận xét</u></b>:</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">- Chương trình trên thực hiện phép nhân hai số lớn được nhập từ bàn phím. Kết quả phép nhân được hiển thị trên màn hình.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;- Lưu ý:&nbsp; Khi sử dụng mảng để lưu kết quả phép nhân, độ dài của mảng kết quả lớn hơn hoặc bằng tổng độ dài của hai số (xâu).</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;- Ta có thể thay đôi kiểu vào ra dữ liệu cho chương trình trên bằng cách sử dụng kiểu dữ liệu tệp.<a name="_Toc358416068"></a></span></span></span><br  />
<br  />
<span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:&#039;Times New Roman&#039;,serif"><a name="_Toc451156717"></a><a name="_Toc358416069"><b><span style="font-size:16.0pt"><span style="line-height:150%">III. KẾT LUẬN</span></span></b></a></span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:130%"><span style="font-family:&#039;Times New Roman&#039;,serif">Ngôn ngữ lập trình nói chung đóng vai trò rất quan trọng trong việc xây dựng các chương trình ứng dụng để phục vụ cho cuộc sống. Nhờ sự phát triển của tin học (trong đó các nhà lập trình chuyên nghiệp đóng vai trò không nhỏ)&nbsp; mà hiện nay hầu hết các lĩnh vực trong xã hội đã ứng dụng được tin học để giải quyết công viêc nhanh, hiệu quả và chính xác hơn.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:130%"><span style="font-family:&#039;Times New Roman&#039;,serif">Hiện nay, ngôn ngữ lập trình Pascal đã trở thành ngôn ngữ lập trình phổ biến nhất trên thế giới sử dụng trong lĩnh vực giảng dạy. Trong quá trình giảng dạy, các thầy cô có thể đưa ra các vấn đề như lập trình các game nhỏ…để các em có thể chứng tỏ được khả năng của mình làm cho học sinh yêu thích môn học, ham học hỏi và &nbsp;sáng tạo.</span></span></span><br  />
<span style="font-size:14pt"><span style="line-height:130%"><span style="font-family:&#039;Times New Roman&#039;,serif">Đề tài này mang tính thực tiễn rất cao cụ thể là: &nbsp;Các em có thể sử dụng kiến thức lập trình để gải các bài toán thực tế thường gặp, các bài toán tính toán với số lớn. Kết quả là có rất nhiều em đã dễ dàng vận dụng được kiến thức để giải các bài toán lặp do giáo viên đặt ra.&nbsp;</span></span></span><br  />
&nbsp;
		</div>
	</div>
	<div id="footer" class="clearfix">
		<div id="url">
			<strong>URL của bản tin này: </strong><a href="https://thptphuquoc.edu.vn/cac-cau-lac-bo/chuyen-de-xu-ly-so-nguyen-lon-trong-pasxal-50.html" title="Chuyên đề xử lý số nguyên lớn trong Pascal">https://thptphuquoc.edu.vn/cac-cau-lac-bo/chuyen-de-xu-ly-so-nguyen-lon-trong-pasxal-50.html</a>

		</div>
		<div class="clear"></div>
		<div class="copyright">
			&copy; Trường THPT Phú Quốc
		</div>
		<div id="contact">
			<a href="mailto:webmaster@thptphuquoc.edu.vn">webmaster@thptphuquoc.edu.vn</a>
		</div>
	</div>
</div>
        <div id="timeoutsess" class="chromeframe">
            Bạn đã không sử dụng Site, <a onclick="timeoutsesscancel();" href="https://thptphuquoc.edu.vn/#">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://thptphuquoc.edu.vn/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="nv4c_t8851",nv_check_pass_mstime=1738000,nv_area_admin=0,nv_safemode=0,theme_responsive=1,nv_is_recaptcha=0;</script>
<script src="https://thptphuquoc.edu.vn/assets/js/language/vi.js"></script>
<script src="https://thptphuquoc.edu.vn/assets/js/global.js"></script>
<script src="https://thptphuquoc.edu.vn/themes/default/js/news.js"></script>
<script src="https://thptphuquoc.edu.vn/themes/default/js/main.js"></script>
<script src="https://thptphuquoc.edu.vn/themes/default/js/custom.js"></script>
<script type="application/ld+json">
        {
            "@context": "https://schema.org",
            "@type": "Organization",
            "url": "https://thptphuquoc.edu.vn",
            "logo": "https://thptphuquoc.edu.vn/uploads/baner.jpg"
        }
        </script>
<script src="https://thptphuquoc.edu.vn/themes/default/js/bootstrap.min.js"></script>
</body>
</html>