Show Example
优质
小牛编辑
138浏览
2023-12-01
下表显示了F#语言支持的所有算术运算符。 假设变量A保持10,变量B保持20然后 -
操作者 | 描述 | 例 |
---|---|---|
+ | 添加两个操作数 | A + B将给出30 |
- | 从第一个减去第二个操作数 | A - B将给-10 |
* | 将两个操作数相乘 | A * B将给出200 |
/ | Divides numerator by de-numerator | B/A会给2 |
% | 模数运算符和整数除法后的余数 | B%A将给出0 |
** | 指数运算符,为另一个运算符提供操作数 | B ** A将给出20 10 |
例子 (Example)
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