Nhập môn lập trình

87 5 0
Nhập môn lập trình

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

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Các lĩnh vực chính của công nghệ thông tin bao gồm quá trình tiếp thu, xử lý, lưu trữ và phổ biến hóa âm thanh, phim ảnh, văn bản và thông tin số bởi các vi điện tử dựa trên sự kết hợp giữa máy tính và truyền thông.[4] Một vài lĩnh vực hiện đại và nổi bật của công nghệ thông tin như: các tiêu chuẩn Web thế hệ tiếp theo, sinh tin, điện toán đám mây, hệ thống thông tin toàn cầu, tri thức quy mô lớn và nhiều lĩnh vực khác. Các nghiên cứu phát triển chủ...

Y F T n sf o A B B Y Y.c bu to re he C lic k he k lic C w om w w w w rm y ABB PD re to Y 2.0 2.0 bu y rm er Y F T n sf o ABB PD er Y w A B B Y Y.c GV: Nguy n V n S n THU T L P TRÌNH GV: Nguy n V n S n CH NG I GI GI II THI THI U U 1 om Y F T n sf o A B B Y Y.c bu to re he C lic k he k lic C w om w w w w rm y ABB PD re to Y 2.0 2.0 bu y rm er Y F T n sf o ABB PD er Y w A B B Y Y.c GV: Nguy n V n S n CÁC B C L P TRÌNH Tìm hi u m c ích, u c u c a tốn Mơ t gi i thu t v s Vi t ch ng trình - Các l nh s p x p tu n t - Các l nh s p x p theo ki u r nhánh Nh p ch y th S a ch ng trình ki m tra k t qu ng d ng b o trì ch ng trình GV: Nguy n V n S n GI I THU T Ví d gi i ph ng trình b c nh t ax+b=0, l n t ta làm nh sau: - Nh p h a, b -N ua=0 ub=0 ng -N ua * Các b c làm Vô s nghi m cl i Vô nghi m x = -b/a gi i PT b c nh t g i ngôn ng gi i thu t om Y F T n sf o A B B Y Y.c bu to re he C lic k he k lic C w om w w w w rm y ABB PD re to Y 2.0 2.0 bu y rm er Y F T n sf o ABB PD er Y w A B B Y Y.c GV: Nguy n V n S n Gi i thu t m t dãy ch n rõ ràng h u n, g m thao tác mà ng i hay máy móc có kh ng th c hi n nh m t c m c tiêu GV: Nguy n V n S n MÔ T GI I THU T Ngôn ng gi i thu t: - Ký hi u, ký t , chu i, ký s -B khóa bi u di n l nh nh ; b t ho c… là…thì; khi; khi… thì; u; n u… thì; om Y F T n sf o A B B Y Y.c bu to re he C lic k he k lic C w om w w w w rm y ABB PD re to Y 2.0 2.0 bu y rm er Y F T n sf o ABB PD er Y w A B B Y Y.c GV: Nguy n V n S n Ví d : gi i thu t gi i pt b c t u Ki u d li u c a bi n Nh p h a; Khi a nh p h b, c; delta = b*b – *a*c; u delta < [ng pt vô nghi m c l i] u delta = [ng c l i] pt có nghi m kép pt có nghi m phân bi t Xem k t qu ; t thúc GV: Nguy n V n S n U GI I THU T u gi i thu t dùng ng kh i hình h c t di n t gi i thu t u ho c k t thúc Nh p xu t d li u Tính tốn Kh o sát u ki n In d li u (k t qu ) ng i c a gi i thu t om Y F T n sf o A B B Y Y.c bu to re he C lic k he k lic C w om w w w w rm y ABB PD re to Y 2.0 2.0 bu y rm er Y F T n sf o ABB PD er Y w A B B Y Y.c GV: Nguy n V n S n Ví d l u gi i thu t gi i pt b c nh t ax + b = t u Nh p a,b úng b=0 a=0 sai Vô nghi m úng Vô s nghi m sai x= - b/a Nghi m x t thúc GV: Nguy n V n S n NGƠN NGƠN NG NG PP TRÌNH TRÌNH CC om Y F T n sf o A B B Y Y.c bu to re he C lic k he k lic C w om w w w w rm y ABB PD re to Y 2.0 2.0 bu y rm er Y F T n sf o ABB PD er Y w A B B Y Y.c GV: Nguy n V n S n Ngôn ng C Dennish Ritchie xu t t i phòng thí nghi m Bell) vào nh ng n m 70 n n m 1978 giáo trình “Ngơn ng p trình C” cho tác gi vi t c xu t b n ph bi n r ng rãi Hi n ngôn ng C c h u h t n c dùng y cho sinh viên chuyên ngành máy tính 10 GV: Nguy n V n S n T P KÝ T Ngôn ng C - CHARACTER SET c xây d ng b ký t : - 26 ch hoa : A …Z - 26 ch th - 10 ch ng : a … z : 0…9 - Các ký hi u toán h c : +,-,*,/,=,() - Ký t ch n i : _ - Các ký hi u c bi t: ,;:[]{}?!&%#$ - Ký t space (kho ng tr ng) dùng cách t 11 om Y F T n sf o A B B Y Y.c bu to re he C lic k he k lic C w om w w w w rm y ABB PD re to Y 2.0 2.0 bu y rm er Y F T n sf o ABB PD er Y w A B B Y Y.c GV: Nguy n V n S n T KHĨA – KEY WORDS khóa nh ng t có m t ý ngh a xác nh Nó dùng di n t phát bi u nh khai báo ki u d li u, vi t toán t câu l nh 12 GV: Nguy n V n S n Nhóm t khai báo ki u d li u: Ki u s nguyên : char , int , short , unsigned , long Ki u s th c: float , double Ki u r i r c : enum Ki u c u trúc : struct , union Ki u r ng: void nh ki u: typedef Khai báo h ng: const , Khai báo bi n: static , extern , auto, register, volatile 13 om Y F T n sf o A B B Y Y.c bu to re he C lic k he k lic C w om w w w w rm y ABB PD re to Y 2.0 2.0 bu y rm er Y F T n sf o ABB PD er Y w A B B Y Y.c GV: Nguy n V n S n Nhóm t dành cho phát bi u: Phát bi u ch n : if , else , switch , case , default Phát bi u l p: for , while , khóa goto u n: break , continue , return , 14 GV: Nguy n V n S n TÊN ( NH DANH) - IDENTIFIER Tên t : dùng xác nh i t ng khác ch ng trình nh : tên h ng, tên bi n, tên ng, tên hàm… Các t C phân bi t ch hoa ch sensitive) th ng (case- t u c a tên ph i ký t ch ho c ký t ch i, ký t sau ký t ch , s , g ch n i _ 15 om Y F T n sf o A B B Y Y.c bu to re he C lic k he k lic C w om w w w w rm y ABB PD re to Y 2.0 2.0 bu y rm er Y F T n sf o ABB PD er Y w A B B Y Y.c GV: Nguy n V n S n Ví d : Tên úng : ham_fx, DEQUI, _BT1 Tên sai : 4abc : ký t u tiên s k#7 : s ng ký t # f(x) : s ng d u ngo c bai tap: có kho ng tr ng bai-tap: s ng d u g ch ngang 16 GV: Nguy n V n S n CÁC KI U D Ki Ki ký Ki Ki u u t u u LI U C B N cho s nguyên: char , int , long cho ký t :char (l u tr ng mã ASCII c a ) r i r c : enum cho s th c :float , double , long double 17 om Y F T n sf o A B B Y Y.c bu to re he C lic k he k lic C w om w w w w rm y ABB PD re to Y 2.0 2.0 bu y rm er Y F T n sf o ABB PD er Y w A B B Y Y.c GV: Nguy n V n S n Kích th c t m tr a ki u d li u ph thu c vào trình biên ch ( xem file limit.h float.h ) Ki u unsigned char char enum unsigned int short int int unsigned long long float double long double bitt bits bits 16 bits 16 bits 16 bits 16 bits 32 bits 32 bits 32 bits 64 bits 80 bits m tr 255 -128 127 -32,768 32,767 65,535 -32,768 32,767 -32,768 32,767 4,294,967,295 -2,147,483,648 2,147,483,647 3.4 * (10-38) 3.4 * (10+38) 1.7 * (10-308) 1.7 * (10+308) 3.4 * (10-4932) 1.1 * (10+4932) 18 GV: Nguy n V n S n H NG - CONSTANT H ng i l ng mà giá tr a khơng thay i q trình tính tốn Cách 1:Dùng macro Thí d : #define PI 3.141592 Cách 2: nh ngh a h ng khơng ki u Thí d : const MaxnN=100; Cách 3: nh ngh a h ng có ki u Thí d : const long MaxSalary=12000000; Cách 4: Vi t th ng tr ng ch ng trình 19 10 om Implicit differentiation technique (to find dy dx for an equation containing y and x) Step Differentiate both sides of the equation, treating y as a function of x, we get another equation with the unknown dy dx Step Solve the obtained equation for N Dinh and Guy Vallet dy dx Chapter DIFFERENTIATION Implicit differentiation EXAMPLE (a) Find yЈ if x ϩ y ෇ 6xy (b) Find the tangent to the folium of Descartes x ϩ y ෇ 6xy at the point ͑3, 3͒ (c) At what points on the curve is the tangent line horizontal or vertical? SOLUTION (a) Differentiating both sides of x ϩ y ෇ 6xy with respect to x, regarding y as a function of x, and using the Chain Rule on the y term and the Product Rule on the 6xy term, we get 3x ϩ 3y yЈ ෇ 6y ϩ 6xyЈ or We now solve for yЈ : x ϩ y yЈ ෇ 2y ϩ 2xyЈ y yЈ Ϫ 2xyЈ ෇ 2y Ϫ x ͑y Ϫ 2x͒yЈ ෇ 2y Ϫ x yЈ ෇ N Dinh and Guy Vallet 2y Ϫ x y Ϫ 2x Chapter DIFFERENTIATION Implicit differentiation y (3, 3) N Dinh and Guy Vallet x Chapter DIFFERENTIATION Implicit differentiation EXAMPLE Find yЈ if sin͑x ϩ y͒ ෇ y cos x SOLUTION Differentiating implicitly with respect to x and remembering that y is a function of x, we get cos͑x ϩ y͒ ؒ ͑1 ϩ yЈ͒ ෇ 2yyЈ cos x ϩ y 2͑Ϫsin x͒ (Note that we have used the Chain Rule on the left side and the Product Rule and Chain Rule on the right side.) If we collect the terms that involve yЈ, we get cos͑x ϩ y͒ ϩ y sin x ෇ ͑2y cos x͒yЈ Ϫ cos͑x ϩ y͒ ؒ yЈ So yЈ ෇ y sin x ϩ cos͑x ϩ y͒ 2y cos x Ϫ cos͑x ϩ y͒ N Dinh and Guy Vallet Chapter DIFFERENTIATION Local linear approximation Differentials Let f be a function Assume that f has its derivative f (x0 ) at x0 Let ∆x = x − x0 , ∆y = f (x) − f (x0 ) Then by definition of derivative ∆y dy = lim dx ∆x→0 ∆x Therefore, as long as ∆x is close to (but ∆x = 0), dy ∆y dy ≈ , or, ∆y ≈ · ∆x = f (x0 ) · ∆x dx ∆x dx (1) The expression f (x0 ) · ∆x is called the differential of f at x0 and denoted by dy or df Thus, dy ≡ df := f (x0 ) · ∆x N Dinh and Guy Vallet Chapter DIFFERENTIATION Local linear approximation Differentials y Q y=ƒ R Îy P dx=Î x x N Dinh and Guy Vallet dy S x+Ỵ x Chapter DIFFERENTIATION x Local linear approximation Differentials If f (x) = x for all x then df = dx = · ∆x and hence, ∆x = dx For this reason, differential of f is often written in the form dy = f (x0 ) · dx Now, the formula (1) can be rewritten as ∆y ≈ dy, or, f (x0 + ∆x) ≈ f (x0 ) + f (x0 ) · ∆x (2) The formula (2) is called the linear approximation of f at x0 It is useful to evaluate approximately the value f (x0 + ∆x) when ∆x is small and f (x0 ), f (x0 ) are known (often much easier than evaluate directly from the formula of f , see examples below) N Dinh and Guy Vallet Chapter DIFFERENTIATION Local linear approximation Differentials √ Approximate 50 √ √ Note that 49 = So we set y = f (x) = x (x > 0) Let By (2), x0 = 49, ∆x = We have f (x) = 2√ x f (50) = f (49 + 1) ≈ f (49) + f (49) · ≈ + ≈ 7.07107 14 Note: Differentials are also used to estimate errors that might enter into measurements of a physical quantity Example In a precision manufacturing process, ball bearings must be made with a radius of 0.6 millimeter, with a maximum error in the radius of ±0.015 millimeter Estimate the maximum error in the volume of the ball bearing (Answer: ∆V ≈ dV ≈ ±0.0679) N Dinh and Guy Vallet Chapter DIFFERENTIATION Local linear approximation Differentials Differential formulas From the formulas of differentiation, we get the formulas for differentials: d[C] = 0, d[f ± g] = d[f ± d[g], d[fg] = fd[g] + gd[f ], gd[f ] − fd[g] f d[ ] = g g2 N Dinh and Guy Vallet Chapter DIFFERENTIATION Higher order derivatives and differentials To understand the behavior of a function on an interval, it is important to know the rate at which the function is increasing or decreasing The second derivative of the function gives us information on this matter If f is a function then f , its derivative, is also a function, e.g., f (x) = sin x then f (x) = cos x; f (x) = sin x then f (x) = 2x cos x ; The derivative of f , if it exists, is called the second derivative of f , denoted by f N Dinh and Guy Vallet Chapter DIFFERENTIATION Higher order derivatives and differentials The derivative of f , if it exists, is called the third derivative of f , denoted by f By such a way, we can define the nth derivative of f being the derivative of the (n − 1)th derivative of f , denoted by f (n) That is f (n) := f (n−1) Notations: For a function y = f (x), we often write f (x) or f (x) or f (4) (x) or N Dinh and Guy Vallet d 2y dx d 3y dx d 4y dx or or or d f (x) dx d f (x) dx d f (x) , dx Chapter DIFFERENTIATION Higher order derivatives and differentials N Dinh and Guy Vallet Chapter DIFFERENTIATION Higher order derivatives and differentials Note: • s (t) > 0: the car is moving forward; if s (t) < 0: the car is moving backward [Distinguish: velocity from speed] • Think of the practical meaning of the cases: (a) s (t) > and a(t) > 0, (b) s (t) > and a(t) < N Dinh and Guy Vallet Chapter DIFFERENTIATION Higher order derivatives and differentials If we consider the differential dy, dy = y (x)dx, as a function of the (only) variable x Then dy may has a differential: d(dy) := d y = d(y dx) = d(y )dx = (y dx)dx = y (dx)2 =: dx , which will be called second differential of the function y Similarly, in general we can define the nth -order differential d n y := d(d n−1 y) We have: d y = y dx , , d n y = y (n) dx n N Dinh and Guy Vallet Chapter DIFFERENTIATION Exercises of Chapter All exercises are taken from the book of James Stewart (version 2001) Section 3.6 (page243-244) 7, 9, 11, 13, 1424, 25 Section 3.8 (256) 5, 7, 9, 16, 17 N Dinh and Guy Vallet Chapter DIFFERENTIATION ... trung bình 3/ Vi t ch tính: ms ng * c v n chuy n = S l - S ti n ph i tr = S l x 32 x 1) n a ba môn Tốn, Lý, Hóa Tính in ng trình nh p tên hàng, s l - Gi m giá = S l -C (x2 xn ng, n giá c a m

Ngày đăng: 11/05/2021, 03:42

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan