1. Trang chủ
  2. » Tất cả

Dạy câu lệnh lặp với số lần biết trước trong ngôn ngữ lập trình pascal

4 5 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 4
Dung lượng 176,19 KB

Nội dung

Khoa hpc Giao dye DAY CAU LENH LAP V6l SO LAN B I E T T R U 6 C TRONG N G O N N G Q LAP TRINH PASCAL PGS TS LE KHAC THANH; Th S NGUYIN CHI TRUNG Dai hpc Sir Pham Ha Npi 1 Hinh thanh cau lenh Tinh hudn[.]

Khoa hpc Giao dye - DAY CAU LENH LAP V6l SO LAN B I E T T R U C TRONG N G O N NGQ LAP TRINH PASCAL PGS.TS LE KHAC THANH; Th.S NGUYIN CHI TRUNG Dai hpc Sir Pham Ha Npi Hinh cau lenh Td diy, GV gidi thieu eho HS biit ring, de thUc Tinh hudng dan den nhu cau sd dung ciu l§nh hien lap lai 22 lan cdng viee tfnh tdng S + KT6\ gin lip for dupe ehung tdi can nhae lUa chpn la Bdi cho bilnS,ta edthe sddung ciu lenh lipfortrong todn tinh tdng dupe phat bieu ngin gpn nhU sau: ngdn ngd Pascal vdi cu phip nhu sau: "Hdy lap trinh eho may tinh gid trj cua bieu thdc: CO phdp: S = + + + + 21+22 + 23'.' for biln := to De thay tong S ed 11 cap sd hang m i mdi cap sd ; hang cich dIu d hai diu day ludn cd tdng bing Hogtdgng :Td (bilu thdc 1) den 25 Suy tdng S can tinh l i 25 x 11 = 275 (nhin nhim 25 vdi 11 bing cich cdng vdi dupc (bilu thdc 2), biln nhin bao nhi§u gia tri thi ciu rdi viit vio gida va 5) Cich tinh nham giup lenh dupe thUe hien bay nhieu lin HS (hpc sinh) de dang kiem tra duac kit qui chay Nhin vio bing md phdng tren, ta thay: Viec them chuong trinh tren miy Nlu ta eho bieu thdc cdng dan cic gii tri kieu byte cCia Kvao lam eho lan kinh thi cic em se sa vao tfnh toan kiem chdng va lupt nhan cic gia tri 2,5,9,14,20 cung thudc kieu lang phf thdi gian khdng can thilt, vl mdt tiet hpc byte, din K bing 22 thi gii tri 252 cCia tong S chi ed 45 phut van thudc kieu byte NhUng d lin lap cudi ci;jng, Ngoii Idi giit toin hpe thuan tOy tren, cd mdt K bing 23, gii tri cua S la 275 vUpt ngoii pham cich tfnh khae, dd la cdng lan lupt cac sd hang eua vi kilu byte va ddi hdi phii dupe md t i bang kilu bieu thdc theo thdtutdtrii qua phii D l hiiu each word Cie phan tich tren dan den chuong trinh tfnh nay, GV md t i eho HS qui trinh cdng ddn gia nhusau: tri cua biln /C vio cho bien tong S theo thuat toin program ViDu ; uses crt; sau diy: var K: byte ; S : word ; BUdc ;: Khdi tao S.-a-Zf.-2; begin Budc2: GanS~S + K; eirscr; S:=0; BUdc 3: Nlu K < 23 thi gan K := K + va quay ve for K:=2to 23 S:=S + K; budc writelnCDapsola ',S); Budc 3: DUa gli trj eua S; readin BUdc4: Kit thuc thuat toin Thuat toin tren duac GV dien t i qua bing md phdng sau diy: Lln l|p K S+K 0+2 2+3 5+4 S 2 3 21 22 22 23 252 252 + 23 275 end Ta luu y vdi HS viec khdi tri eho S la ein thilt, va de khdng lam anh hUdng den tdng, ta cho S khdi tri bang thdng qua lenh gin S := 0; Luyen tap ciu lenh lap vol sd lan dinh trudc Sau hinh thinh eho HS eau Idnh lap for, dl luyen tap, ta ed the cho HS giii quylt Bditodn tinh cdn vdi tinh hudng khd khin hon mot chut so vdi KHGD so 67, thang 4-2011 -Khoa hoc Giao dgc tinh hudng Bdi todn tinh tong ndi tren: "Hdy lap Ve phuang dien dUlieu, Bdi todn tinh tong trinh tinh gid tri bieu thdc sau: day can tinh tong l i mdt diy sd lien tue, duac chu y chpn can dUdi l i va can tren la 23 chd khdng chpn can dudi va can tren nhd hpn hoac Idn hon vi 3=^23 + V22 + + >/3+W." nhieu If do, dd phii ke din cac li sau day: Bai toin niy cd 22 dau ein bic hai Idng Y tudng eCia thuat toin la viec tfnh cin eua cie tong dupc thUc hien td ngoai Mdt eieh tdng quit, ta dung mdt biln K lan lupt nhin cac gia tri td den 23, dng vdi moi gia tri cOa K, ta lay -Js + K gdi vao S (Biln S dupe khdi trj bing 0) - Do tong eie sd tU nhien td din 23 la 275 vUpt ngoai 255 nen ta phii khai bio bien S ed kilu wprd Vl phuong dien trilt hpc, dilu minh hpa quy luat "lupng doi, chdt doi" Quan diem trilt hpc se khdng cd eP hdi dupe de cap den, nlu ta chpn day td den 22, vi kit qua tong van thudc kilu byte Ta din chuong trinh tren sang cda sd thU hai de - Nlu ta cho tfnh tdng td din 100 thi cung de thu dupe mdt chuong trinh mdi bing cich sda mdt sd chd Chuong trinh the hien y tudng thuat ding nham tdng la 5050 bang cdng thdc (1 + 100) X 50 (cich ma Gau-xP da lam dng mcl toin tren nhusau tuoi) Nhung vi tong qui de nhan vupt qui program ViDu ; uses crt; 255 nen sU canh bio viec tran d nhd se khdng may var K : byte ; S : real; ngae nhien vdi cic em Dd glat minh khdng cao vl begin cac em da chuan bj td trUdc khdng mat cinh giac nhu 275 eirser; S:=0; Ve phuang dien thudt todn, ta da hudng cho HS for K := to 23 S:- sqrt(S -i- K); xiy dung hai thuat toin giii Bdi todn tinh tdng writelnCDapsola ' , : : ) ; Thuat toan thd nhat (tfnh theo cdng thde (2 + 23) readin; X 11 = 275), dUPng nhien la sang tao, thdi gian end thuc hien nhanh NhUng thuat toan thd hai (cdng Ldi ban ve phuong phap giing day lan lupt theo thd tu tang dan td trai sang phii) la Ve phuang dien giao tiep, tao tinh hudng dayphong each lam viee cua may tfnh, die t i cic cdng viee dupe lap lai vdi sd lan biet trUde cau lenh lip for, ta can mdt biln lan lupt duyet qua cac gii tri liin tue v i dem dupe de diiu khien Ve phuang dien qud trinh, viec ta dung bing md vdng lap vdi sd lan lap biit trUdc Tai thdi dilm nay, phdng qua trinh cdng don theo K nhU tren ehfnh ta luu y eho HS mdi quan he v l gia trj gida la giup HS hinh dung qui trinh xiy bin va de biet duac sau td khda bd nhd cCia miy tfnh nd thuc hien viee tinh thuc hien bao nhieu lan tong qua eiu lenh for Mdt sd ddng bing Muc dich chdc ndng eua ta l i hinh vdng md phdng, ta de dau ba cham d l cho HS tu for cho hoc sinh, mue^chphuang tiin l i tinh tdng tuong tU- Viec tich day sd eae sd doe lap la eae sd tU nhien td din 23 Phuong chim cua ta tuduy phin tieh la thUe iiiln mue dfch chdc nang thdng qua mue Td chuong trinh tinh tong sang chuong trinh dfch phuong tien Vi vay ma bii toin minh hoa tfnh can bac hai la nhim nhdng y tudng sau diy: (muc dfch phuong tien) ta chpn eing dpn giin Ren luyin phuong dien gidi quyet van de Hai bi v l mat tinh toin, eang d l hieu ve mat cau true thi eing tdt Vile tinh tdng td din 23 ehi la phuong toin Bdi todn tinh tdng va Bdi todn tinh edn khic tiin true quan minh hoa cho HS de nam bat dupe v l y nghTa toan hpc nhUng quy trinh tiep can eu phip va hoat ddng cCia ciu lenh lap for Sau giii quylt tdng cdng doan la tUOng tU nhU HS da hieu biit v l vdng for thdng qua vf du don Dau tien gan cho biln luu gid kit qui bang Cho giin ban dau, ta eho hpc sinh van dung vio tfnh biln K lan lUpt duyet qua cac gii trj td gia trj ban bieu thde cd 22 dau ein bic hai Idng d l HS dau den gia tri kit thue Bditodn tinh tong thi lay S + K rdi gan eho bien S, d Bdi todn tinh edn thi lay thay tam quan trpng eua vdng for •JS + K rdi gin eho biln S KHGD so 67, thdng 4-2011 35 Khoa hpc Giao dgc Rin kithugt Idp trinh tddudilin HS biit tin dung eirser; S:=23; nhdng chuong trinh da biet d l sda ehda v i tao for K:= 22 downto S :=S + K; chuong trinh giii bii toin mdi Vdi chu y niy, writelnCDapsola ',S); chuong trinh mdi, ta gid nguyen can dudi v i can readin trIn 23; gid nguyen ngd cinh eua eau lenh dua end thdng tin ra; khai bio biln S ddc lap d l sda kilu dd chuong trinh tren, ta cung lUu y eho HS each lilu eua bien td word sang real; cdn thin ehuong khdi trj "sdm" cho biln tich luy tdng S bing eau trinh ta ehi can them ham sqrt v i them ehi thj :0:4 lenh gin S := 23 Khi dd ciu linh for, biln K d4 in so thuc dau phay tTnh d dap sd chi cin lui td gia tri 22 xudng gii tri 2, do sd lin Nhae nhd HS phuang diin sddung may tinh diin lap glim xuong edn 21 lan tCt Ren luyen cho HS cic thao tic co bin ve quin If De HS hdng thu va thay tic dung cua ciu lenh tep va soan thio, bang cic cdng viec ch^p va din chuong trinh sang cda sd khae, ghi lai tep vdi lap for dang lui, GV tiep tuc cho eae em xem may ten mdi, sda lai bing each them, bdt, chen, xoi d l giii bii toin tinh S sau diy: dupc chuong trinh tinh cin Bdi dudng quan diem triet hgc NhU da de cap TinhS , V2 + )/3+- + V224-V23 d trdn, ta chu y chpn eie can eho day sd can tfnh tong la v i 23 de thay dupc gia trj cUa bien tdng Y tudng tfnh toin cho bai toin niy cung la lin chuyin td mien byte sang mien word, qua dd thay lupt tinh td ngoai tuong tU nhu bai toin dupe quy luit eua cap pham tru chat va lUpng Mat tfnh can da giii d tren Viec dung for dang lui d day khie, viec ehuyen td bai toan tinh tong sang bai la thich hpp Ta din chuong trinh d cda so thd hai toin tfnh can bac hai da lam cho bien S chuyin td sang cda sd thdtu, rdi sda lai de cd chuong trinh miln word sang miln real, qua thiy dupe quy mdi: luat ci!ia cap pham tru hinh thde v i ndi dung program ViDu ; uses crt; DownTo var K : byte; S : real; Sau HS d i nim dupe hoat ddng cOa cau lenh begin lap for dang tien, ta hinh cho cic em ciu cirscr; S:=sqrt(23); lenh lap for dang lui Ta xet lai Bai todn tinh tong for K := 22 downto (khdng nen lay vf du khie) S:=sqrt(S + K); Theo tfnh chat giao hoin cilia phep cdng, tdng writein (' Dap so la ', S: 0:4); tren edn edthe tinh theo thdtutd phii qua trii, tde readin l i = 23-1-22 + 21+ -I- +3 + 2.DlthUchiln dilu nay, ngdn ngd Pascal cd ciu lenh for dang lui end vdi cu phip v i hoat ddng nhu sau: Hai vdng for I6ng CO phdp: for bidn := downto ; Hogtdgng: Td den biln nhin bao nhieu gia tri thi ciu lenh dupe thUc hien bay nhieu lan Ta dan chUPng trinh tfnh tdng d cda s6 thd nhat sang cda so thd ba v i sda lai nhusau: program ViDu ; uses crt; var begin 36 K : byte ; S ; word ; Day ciu lenh lap for can phii tiin din day hoat ddng cCia cau lenh lap for Idng Vi sau niy HS se dung den cau trOe lam viee vdi ming ehilu va nhieu tinh hudng khic Cich tiip can cau true for Idng mdt cich tu nhien nhat l i ta dUa nhin xet: Trong cu phip eua eiu linh lip forth! ban thin sau td khda eung cd t h i la eau lenh cd eau true nhu eiu lenh hpp (begin end), cau lenh re nhinh (if-then) va tat nhien cd the la ciu l4nh for-do khic Hoat ddng ci\a for Idng ed t h i hieu nhu sau: dng vdi tdng gii tri eua bien dilu KHGD so 67, thdng 4-2011 ^ifl^^ilnHiJukhiln vdng for b^n ngoii, may se thUc hi^n mdt lan vdng for ben -Khoa hpc Gido due trau giaO; readin Ta minh hpa vdng for Idng bing viec cho end HS quan sit kit qui thuc hien ehUOng trinh Ket luan eho hien len hinh ddng diu eua bing nhin ChUPng trinh nhu sau: Lan dau tien day eho HS v l ciu lenh lap for, theo program ViDu; uses crt; ehung tdi, tiin trinh din dat HS ITnh hdi kiln thde cung vdi viec lUa chpn cac tinh hudng da neu l i var d , e: byte; phCi hpp, b^ vi nd kit hpp dupc cic Uu dilm quan begin trpng nhU: eirser; -Trong thdi gian ngin, GV giup HS hieu dupc cu for d := to phip va hoat ddng eua ciu lenh lap for dang tiin begin va dang lui, cua cau true lap for Idng for e := to - Vdi phuong chim thUe hien muc dfch chdc write (d: 3,' ',c,' =', d*e: 2); ning thdng qua mue dfch phuong tien, ta ddng writein; thdi dat dupc cic y v l phuong phap day hpe nhU: bdi dUdng quan diem triet hpe, dat dupe end; nhilu phUPng di^n nhU: giao tiip, thuat toin, dd readn lieu, qua trinh, sddung may tfnh, kT nang lip trinh end td dudi len va kT nang giii quylt van de Nhan xet Cac bai toan khd hon va hay hon sd dung ciu Ta cho in ddng diu tien cQa bing nhin m i lenh lap for se cd eP hdi dupc gidi thieu d nhdng tilt hpe sau khdng cho in c i bing nhin la de cho HS de nhin ddng ehi nhin gii tri, edn cot nhin gii tri Nlu in ci bing nhin thi ddng va cot deu nhan gia tri lim cho vi^c phan biet gia tri eua ddng v i gii tri cua edt la khdng true quan TAILIIUTHAMKHAO [1] L^ Khae Thinh, Phuong phdp dgy hgc dgi cuang mdn tin hgc, NXB Dai hpe SU Pham Ha Npi, Van dung: Ta cd the y#u cau HS lip trinh eho 2006 miy giii bii toin "Cd 100 trdu, 100 bd cd Trdu [2] Le Khae Thinh, Phuang phdp dgy hge chuyin ddng dn 5, trdu ndm dn 3, lu khu trdu gid eon mot ngdnh mdn tin hgc NXB Dai hpe SU Pham Ha Ndi, bo Hdi moi logi ed may eon T 2008 Ta gpi so triu ddng la d, so triu nam l i n Khi d [3] HdCam Hi (Chu bien), Le KhacThanh, Nguyin Ianluptduyltquacicgiitritd0den20(100bdcd chia cho l i sd bd mdt triu dLhig an), dng vdi ChiTrung, Dgy hge theo chuan kien thde kindng Tin mdi gii trj cOa d, ta cho triu nim n lan lUpt duyet hgc 10, NXB Dai hpc SU Pham Ha Ndi, 2010 [4] Hd Sy Dim (Chu bien) Ho Cam Ha, Tran Dd qua eie gii trj td din 33 Biet d, n ta se tfnh dupc Hung, Nguyen Ddc NghTa, Nguyen ITianh TiJng, sd triu gia la 100 - d - n Chuong trinh nhu sau: Ngd Anh Tuyet, Tin hgc 11, NXB Giio due 2007 program ViDu; uses crt; var d , n: byte; begin cirscr; for d:=Oto 20 for n:=Oto 33 if 5*d + 3*n + (100-d-n)=100then writein (d,' trau dung' ,n,' trau nam' ,100-d-n,' KHGD so 67, thdng - 2011 SUMMARY Pedagogical approaches in teaching the repeatin FOR syntax clause in school informatics often sta from calculating sum of a series This article propos some sample v\/ith effective teaching This teach has achieved many ideas of teaching methods an simple to implement in short teaching period 37 ... thdtutd phii qua trii, tde readin l i = 23-1-22 + 21+ -I- +3 + 2.DlthUchiln dilu nay, ngdn ngd Pascal cd ciu lenh for dang lui end vdi cu phip v i hoat ddng nhu sau: Hai vdng for I6ng CO phdp:... nhieu tinh hudng khic Cich tiip can cau true for Idng mdt cich tu nhien nhat l i ta dUa nhin xet: Trong cu phip eua eiu linh lip forth! ban thin sau td khda eung cd t h i la eau lenh... l i var d , e: byte; phCi hpp, b^ vi nd kit hpp dupc cic Uu dilm quan begin trpng nhU: eirser; -Trong thdi gian ngin, GV giup HS hieu dupc cu for d := to phip va hoat ddng eua ciu lenh lap for

Ngày đăng: 18/11/2022, 15:41

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w