这两天进入写博客阶段了,也为了响应版主的少灌水方针,来顺手贴一些自己写的东西。
这一步分时在看mj老师的c基础中我觉得比较有意思的部分,和大家分享一些。
一、使用临时变量.- int main (void)<span class="token lf" style="box-sizing: border-box; outline: none !important;">
- </span>{<span class="token lf" style="box-sizing: border-box; outline: none !important;">
- </span> int a = 10;<span class="token lf" style="box-sizing: border-box; outline: none !important;">
- </span> int b = 20;<span class="token lf" style="box-sizing: border-box; outline: none !important;">
- </span> int temp = b;<span class="token lf" style="box-sizing: border-box; outline: none !important;">
- </span> b = a;<span class="token lf" style="box-sizing: border-box; outline: none !important;">
- </span> a = temp;<span class="token lf" style="box-sizing: border-box; outline: none !important;">
- </span> return 0;<span class="token lf" style="box-sizing: border-box; outline: none !important;">
- </span>}
复制代码 二、利用加减法- a = b - a;<span class="token lf" style="box-sizing: border-box; outline: none !important;">
- </span> b = b - a;<span class="token lf" style="box-sizing: border-box; outline: none !important;">
- </span> a = a + b;
复制代码
步骤:1. a = (b - a)2. b = b - (b - a) ∴ b = a3. a = (b - a) + a ∴ a = b三、利用异或- a = a ^ b;<span class="token lf" style="box-sizing: border-box; outline: none !important;">
- </span>b = a ^ b;<span class="token lf" style="box-sizing: border-box; outline: none !important;">
- </span>a = a ^ b;
复制代码
步骤1. A = a ^ b3. B = (a ^ b) ^ b ∵(b ^ b) = 0 B = a ^ 0 ∴ B = a 3. A = (a ^ b) ^ a 同理可得 A = b注:大小写区分为了看得清楚
最后我有个问题问一下。怎么设置回复可见,我也想快一点积累分数啊 0.0!
|
|