欧美一区二区三区,国内熟女精品熟女A片视频小说,日本av网,小鲜肉男男GAY做受XXX网站

delphi div函數

錢淋西1年前6瀏覽0評論

Delphi中的div函數用于計算兩個整數相除后的整數商。當整數相除時,返回的是商的整數部分,忽略小數部分。

下面是幾個代碼案例,詳細解釋和說明了delphi div函數的用法。

案例1:

program DivFunctionExample;
<br>
var
dividend, divisor, quotient: Integer;
<br>
begin
dividend := 10;
divisor := 3;
quotient := dividend div divisor;
<br>
  WriteLn('The quotient of ', dividend, ' divided by ', divisor, ' is ', quotient);
end.

執行以上代碼,輸出結果為:

The quotient of 10 divided by 3 is 3

在這個例子中,dividend被除數的值為10,divisor除數的值為3。使用div函數將這兩個值相除,得到的商是3。

案例2:

program DivFunctionExample;
<br>
var
dividend, divisor, quotient: Integer;
i: Integer;
<br>
begin
dividend := 100;
divisor := 7;
<br>
  for i := 1 to dividend do
begin
if i mod divisor = 0 then
WriteLn(i, ' is divisible by ', divisor, ', quotient is ', i div divisor);
end;
end.

執行以上代碼,輸出結果為:

7 is divisible by 7, quotient is 1

14 is divisible by 7, quotient is 2

21 is divisible by 7, quotient is 3

28 is divisible by 7, quotient is 4

35 is divisible by 7, quotient is 5

42 is divisible by 7, quotient is 6

49 is divisible by 7, quotient is 7

56 is divisible by 7, quotient is 8

63 is divisible by 7, quotient is 9

70 is divisible by 7, quotient is 10

77 is divisible by 7, quotient is 11

84 is divisible by 7, quotient is 12

91 is divisible by 7, quotient is 13

98 is divisible by 7, quotient is 14

在這個例子中,我們使用了for循環,從1到100,找出可以被7整除的數字。通過使用div函數,我們可以得到相應的商。

案例3:

program DivFunctionExample;
<br>
var
dividend, divisor, quotient: Integer;
<br>
begin
dividend := -10;
divisor := 3;
quotient := dividend div divisor;
<br>
  WriteLn('The quotient of ', dividend, ' divided by ', divisor, ' is ', quotient);
end.

執行以上代碼,輸出結果為:

The quotient of -10 divided by 3 is -3

在這個例子中,dividend被除數的值為-10,divisor除數的值為3。盡管dividend是一個負數,但是div函數仍然可以正確計算出商的值為-3。

Delphi的div函數用于計算兩個整數相除后的整數商。它忽略小數部分,返回的是商的整數部分。無論被除數、除數都是正數還是負數,div函數都可以正確計算出商的值。在編寫需要整數運算的程序時,div函數是一個非常有用的工具。