Files
spl/stage1/test03_arithmetic.spl
2026-07-05 21:45:43 +08:00

57 lines
1.1 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* ===== 模块2表达式 =====
* test03_arithmetic — 算术运算
* 难度1/5
* 验证点:加、减、乘、除、取模、负数、混合运算优先级
*/
fn main() i32 {
/* 加法 */
var a := 12 + 34;
if a != 46 { ret 1; }
/* 减法 */
var b := 100 - 23;
if b != 77 { ret 2; }
/* 乘法 */
var c := 7 * 8;
if c != 56 { ret 3; }
/* 除法 */
var d := 100 / 3;
if d != 33 { ret 4; }
/* 取模 */
var e := 100 % 3;
if e != 1 { ret 5; }
/* 负数 */
var f := -5;
if f != -5 { ret 6; }
/* 负数运算 */
var g := -10 + 3;
if g != -7 { ret 7; }
/* 运算优先级:乘优先于加 */
var h := 2 + 3 * 4;
if h != 14 { ret 8; }
/* 括号改变优先级 */
var i := (2 + 3) * 4;
if i != 20 { ret 9; }
/* 连续运算 */
var j := 1 + 2 + 3 + 4 + 5;
if j != 15 { ret 10; }
/* 混合运算 */
var k := 10 * 2 - 8 / 4;
if k != 18 { ret 11; }
/* 负数取模 */
var l := -7 % 3;
if l != -1 { ret 12; }
ret 0;
}