Fsharp-arithmetic-operators

提供:Dev Guides
移動先:案内検索

F#-算術演算子

次の表は、F#言語でサポートされているすべての算術演算子を示しています。 変数Aが10を保持し、変数Bが20を保持すると仮定します-

Operator Description Example
+ Adds two operands A + B will give 30
- Subtracts second operand from the first A - B will give -10
* Multiplies both operands A* B will give 200
/ Divides numerator by de-numerator B/A will give 2
% Modulus Operator and remainder of after an integer division B % A will give 0
** Exponentiation Operator, raises an operand to the power of another B**A will give 2010

let a : int32 = 21
let b : int32 = 10

let mutable c = a + b
printfn "Line 1 - Value of c is %d" c

c <- a - b;
printfn "Line 2 - Value of c is %d" c

c <- a * b;
printfn "Line 3 - Value of c is %d" c

c <- a/b;
printfn "Line 4 - Value of c is %d" c

c <- a % b;
printfn "Line 5 - Value of c is %d" c

あなたがプログラムをコンパイルして実行すると、次の出力が得られます-

Line 1 - Value of c is 31
Line 2 - Value of c is 11
Line 3 - Value of c is 210
Line 4 - Value of c is 2
Line 5 - Value of c is 1