delphi基本资料.doc_第1页
delphi基本资料.doc_第2页
delphi基本资料.doc_第3页
delphi基本资料.doc_第4页
delphi基本资料.doc_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

PASCAL CH3: Arithmetic Operation 算術運算+ - PASCALChapter 3: Arithmetic Operation in PASCAL第三課:PASCAL的算術運算3.1 Arithmetic Operation算術運算Mathematical Operation數學運算PASCAL OperatorPASCAL 運算符Operation運算Example例子+Addition 加法5 + 121.2 + 3.4-Subtraction 減法4 23.2 2.1-Unary Minus 一元減法-4-8.8*multiplication 乘法4 * 87.2 * 1.2/Real Division實 數 除 法4 / 24.5 / 1.5DivInteger Division整 數 除 法23 div 3modModModulo ( Reminder )模數 ( 餘 數 )23 mod 3I. The operators can be use in numbers, constants and variables.以上的運算符可以用於數字、常量及變量。II. In an operation, it can have both integer type and real type variables:在運算過程中,可以同時包括整數及實數類:A. If in a operation have both integer and real data types, the output value must be ( real ) type.如果在一個算術運算中包括整數和實數類,其輸出結果一定是( 實 數 )類。B. If the operation involved / (real division), the output value must be real type.如果在運算式中掀涉 / (實數除法),其輸出結果一定是實數。Operation運算Example例子Result結果Result Type (I: Integer 整數)結果類型 (R: Real Type 實數)+Addition加法123 + 321444I4.4 + 5.59.9R-Subtraction 減法369 123246I0.5 0.1450.355RMultiplication乘法11 * 555I2.4 * 0.51.2RReal Division實數除法600 / 2030.0R600.0 / 2.030.0R3.1.1 Unary Minus一元減法It is a sign to negate the value of an operand. For example,這是一個將數值改為其相反數值的符號。例如:1234 ( -1234 )3.1.2 Integer Division 整數除法The operand div to find the ( quotient ) of am integer division. The reminder will be neglected.其運算符是 div ,並用來找出整數除法的( 商 ),並捨去其餘數。Example例子Mathematical Operation數學運算Result結果25 div 7 3 Quotient 商7 )2521 4 Reminder 餘數3Expression 表達式Result結果5 div 808 div 518 div 5-1-8 div 5-1-8 div 518 div 0Undefined8.5 div 5Undefined3.1.3 Modulo Operation 模數(餘數)運算I. The operator mod is used to find the ( reminder ) in an integer division and the quotient will be neglected.運算元 mod 用作找出整數除的( 餘 數 ),並捨其商。II. This operation only allowed for ( integer ) and the divisor must not be ( zero ).此運算只可容許( 整 數 ),而且除數不可以是( 零 )。Expression 表達式Result結果5 mod 858 mod 538 mod 53-8 mod 5-3-8 mod 5-38 mod 808 mod 0UndefinedEvaluate the following arithmetic expression: 估計以下算術運算的答案:Arithmetic Expression算術運算Result 結果(3+4)*5-629-99 div 9-11-6 mod (2+4)0-(1998 mod 25) * ( 8 div 3 )-463.2Converting Mathematical Expression in PASCAL數學表式在Pascal 上的轉換Mathematical Expression數學表式PASCAL ExpressionPASCAL 表式5 9a2+b2a*a+b*b(F-32)5/9*(F-32)B2-4ACB*B-4*A*C10x310*x*x*xA(-(B/C)A*(-(B/C)a+bcd(a+b)/(c*d)(xy+z)2(xy+z)*(xy+z)a2+b2-4aca*a+b*b-4*a*c3.3 Precedence of Arithmetic Operators 算術運算符優先次序?3+4*5 7*5 353+4*5 3+20 23?When the arithmetic operation involve more than one operators, it is necessary to define clearly the precedence of arithmetic operators:當算術運算掀涉多過一個運算符時,便有需要義清楚運算符執行的優先次序:1.Operator with higher precedence will be evaluated first:先運算有較高優先次序的運算符:Level of Precedence 優先次序Operator運算符1( )2- (unary minus 一元減號)3* , / , mod, div4+, - (subtraction 減法)Example例子:Evaluation Step 運算步驟-X/(Y+Z)1.Value in parentheses括號內之數值+2.Unary minus 一元減號- 3.Real division 實數除法 /2.Operators with same precedence is evaluated from ( left ) to ( right ).若運算符先次序相同,則由( 左 )至( 右 )運算。Example例子:Evaluation Step 運算步驟4/A*C1.Real division 實數除法 / 2.Multiplication 乘數 * 3. Nested parentheses are evaluated from the ( inside out ).嵌套括號由( 內 至 外 )運算。Example例子:Evaluation Step 運算步驟(2 mod (3+4) div 61.Innermost parentheses最內的括號 +2.Outermost parentheses最內的括號 mod3.Integer division 整數除法 div3.4 Arithmetic Functions 算術函數I. Arithmetic function consists of two parts:數學函數包括兩個部份: A. function ( name )/函數( 名 ) sqrt(x) Compare比較: B. function( argument )/函數( 變 元 )II. There is no space between the function name and the parenthesis.函數名與括號之間沒有空格。ArithmeticFunction算術函數Purpose用途ArgumentType變數類型ReturnType轉回類型Example例子abs(x)Return ( absolute ) value of x.得出x的( 絶 對 )值。I / RSame asargument與變元相同abs(-3)3abs(3.5)3.5round(x)Round the x in the nearest integer.得出x四捨五入的值。I / RIround(2.1)2round(2.7)3round(2) 2sqrt(x)Return the ( square root ) of x.得出x 的的正( 平 方 根 )。I / R /+R / +sqrt(9) 3.0sqrt(2) 1.414trucn(x)Return the ( integer ) part of x.得出x的( 整 數 )部份。I / RI trunc(2.1) 2 trunc(5.9) 5 trunc(4) 4random(x)Return a number greater than or equal to zero, but less than x.得出一個大或等於零,但小於x的數。 0 random(x) x I / +I / + rand(3)I : Integer 整數R : Real 實數+ : positive number正數Example例子Program程式Output輸出Remarks備注abs(x)Program abcx;begin writeln(abs(123); writeln(abs(-456); writeln(abs(123.456):1:3); writeln(abs(-323.256):1:3); readln()end.123-456123.456-323.256round(x)program roundx;begin writeln(round(2.5); writeln(round(2.6); writeln(round(-2.5); writeln(round(-2.6); readlnend.23-2-3The PASCAL compiler we used (Bloodshed Dev-Pascal) is round off for value greater than 0.6.本校的Pascal編輯 (Bloodshed Dev-Pascal) 器是五捨六入。trucn(x)program truncx;begin writeln(trunc(2.5); writeln(trunc(2.6); writeln(trunc(-2.5); writeln(trunc(-2.6); readlnend.22-2-2sqrt(x)program sqrtx;begin writeln(sqrt(12); writeln(sqrt(25); writeln(sqrt(3*3+4*4); readlnend.3.46E+00005.00E+00005.00E+0000sqrt(-1) : Undefined未定義random(x)program random1;begin writeln(1st:, rand); writeln(2nd:, rand); writeln(3rd:, rand); writeln(4th:, rand); readlnend.When the function do not have argument type (x), it will return a real value between 0 and 1, that is:當此函數沒有變數類型(x),會得出一個零與一之間的實數。即是: 0random1 program random2;begin writeln(random(100)+1); writeln(random(100)+1); writeln(random(100)+1); writeln(random(100)+1); readlnend.To generate an random integer, a integer argument n can be used and the vaule is:當要得出一個隨機整數,必需輸入一個整數變數n: 0random(n)n 3.5 Assignment Statement 賦值語句 Variable 變量x:=y( Expression 表 式 )The assignment symbol which mean “get the value of”.賦值符,指取其值為。Expression can be a number, ( variable ) or ( constant ).表式可以是數值,( 變 量 )或( 常 量 )。Example例子Result結果program assign1;const three = 3;var x, y, z : integer;begin x :=5; y :=x; z := three; writeln(x, y, z); readlnend.5 5 33.5.1 Assigning Integer and Real Values to Variables給變量賦予整數及實數值Integer can assign to integer and real variable, but real number can only assign to real variable.整數可以配給整數及實數的變數,但實

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论