You are on page 1of 2

TRNG I HC BCH KHOA TP.

HCM Khoa Khoa hc & K thut My tnh

K THUT LP TR NH
Bi tp 1 Tun 2 Cc thnh ph n c bn
Mt prototype c c php khai bo nh sau: [Kiu tr v] [T n hm] ( [Kiu gi tr] 1 [Tn i s]1, , [Kiu gi tr] n [Tn i s]n); V d 1: Cho chng tr nh nhp vo hai s nguyn x v y s tr v tng ca hai s nguyn . Xc nh prototype ca chng trnh. Gii: Chng tr nh tnh tng ca hai s nguy n nn k t qu tr v s l s nguyn (ki u int). Tn hm nn mang ngh a gi nh nn ta t l sum. Lu : tn hm khng c c khong cch . V chng trnh nhp vo hai s nguyn x v y nn ta s c hai i s c kiu s nguyn int l x v y Prototype : int sum (int x, int y) ; [Kiu tr v] : int [Tn hm] : sum [Kiu gi tr] 1 : int [Tn i s]1 : x [Kiu gi tr] 2 : int [Tn i s]2 : y V d 2 : Cho chng tr nh xut ra mn hnh dng ch Hello World !. Vit prototype ca chng trnh ny. Gii : V chng trnh ch cn xut kt qu ra m n hnh m khng c n tr v kt qu , do , kiu tr v s l void. Mt khc, chng trnh cng khng cn nhp vo i s nn phn i s ta c th trng. Prototype : void print () ; Hy xc nh prototype v v flowchart cc chng trnh sau: Bi 1: M t gii thut tnh giai tha kp ca s t nhi n N vi N c nhp t b n phm. Giai tha kp k hiu l n!!, c nh ngha quy nh sau: n 1 1 n!! n(n 2)!! n 2 K thut lp tr nh 501127 HK2/2010-2011 1

TRNG I HC BCH KHOA TP.HCM Khoa Khoa hc & K thut My tnh V d: 8!! = 2 * 4 * 6 * 8 = 384 9!! = 1 * 3 * 5 *7 * 9 = 945 Bi 2: M t thut ton Euclid tm c chung ln nht v bi chung nh nht ca hai s nguy n dng nhp t bn phm. Bi 3: Mt chng trnh nhn mt ng trn tm O(x o,yo) bn knh R. M t gii thut k im tra mt im A(x,y) nm trn, trong hay ngoi ng trn. Bi 4: Cho bng gi bn l in sinh hot bc thang nh sau: STT Mc s dng ca mt h gia nh trong thng Gi bn in (ng/kWh) 1 Cho 50 kWh u tin 600 2 Cho kWh t 51 n 100 1 004 3 Cho kWh t 101 n 150 1 214 4 Cho kWh t 151 tr l n 1 594 M t gii thut tnh tin da tr n bng gi khi ngi dng nhp vo s kWh s dng. Bi 5: M t gii thut chuyn i t C sang F v ngc li. Cho bit: oF = oC * 9/5 + 32 Bi 6: Cho ba c nh ca mt tam gic. H y kim tra xem tam gic n y l tam gic cn, tam gic vung, tam gic vung cn hay l tam gic u.

Bi 7: M t gii thut t m gi tr ln nht (GTLN) v gi tr nh nht (GTNN) c a mt mng N s nguyn nhp t bn phm. Bi 8: Chng tr nh nh p vo 2 s hp l X, Y. Trong , X l thng v Y l nm. Chng tr nh s cho bit thng ca nm c bao nhi u ngy. n gin, cho X = 1, 2, 3, 4 V d: X = 4 v Y = 2010 => 30 ngy. Gi : nm nhun l nm c gi tr chia ht cho 4 nhng khng chia ht cho 100. Ngo i ra, nm c gi tr chia ht cho 400 cng c gi l nm nhun.

-- Ht --

K thut lp tr nh 501127 HK2/2010-2011