AI玩具

茶山项目


C语言筑基期

<h1>超简版C语言小白入门指南</h1> <p><strong>零基础也能看懂的“极简三步走”教程</strong> </p> <hr /> <h2>一、5分钟搞定环境(新手友好版)</h2> <p><strong>推荐选择</strong>: </p> <ol> <li> <p><strong>在线编译器</strong>(免安装)<br /> • <a href="https://www.onlinegdb.com/">GDB Online</a> → 选C语言 → 直接写代码点&quot;Run&quot; </p> </li> <li><strong>VS Code安装包</strong>(本地开发)<br /> • 下载地址:<a href="https://code.visualstudio.com"><a href="https://code.visualstudio.com">https://code.visualstudio.com</a></a><br /> • 装完点扩展→搜“C/C++”→安装第一个插件 </li> </ol> <p><strong>避坑提示</strong>:<br /> • 不要用中文路径保存代码文件(会报错!)<br /> • 代码里的符号必须是英文的(比如分号<code>;</code>不是中文的<code>;</code>) </p> <hr /> <h2>二、第一个程序:会动就行!</h2> <p><strong>复制这段代码</strong>(先感受成功运行的快乐) </p> <pre><code class="language-c">#include &amp;lt;stdio.h&amp;gt; int main() { printf(&amp;quot;恭喜!你写出了第一行代码!\n&amp;quot;); printf(&amp;quot;3秒后显示计算结果...\n&amp;quot;); sleep(3); // 等待3秒(像手机加载动画) printf(&amp;quot;1+1=%d\n&amp;quot;, 1+1); // %d会显示计算结果 return 0; }</code></pre> <p><strong>运行结果</strong>: </p> <pre><code>恭喜!你写出了第一行代码! 3秒后显示计算结果... 1+1=2</code></pre> <p><strong>关键解释</strong>:<br /> • <code>#include &amp;lt;stdio.h&amp;gt;</code> → 让电脑认识<code>printf</code>这个打印命令<br /> • <code>int main()</code> → 所有代码都从这里开始执行<br /> • <code>\n</code> → 相当于手机聊天时按“回车”换行 </p> <hr /> <h2>三、最常用三件套(先会抄再理解)</h2> <h3>1. 变量与输入</h3> <pre><code class="language-c">int age; // 声明一个叫age的“数字盒子” printf(&amp;quot;请输入你的年龄:&amp;quot;); scanf(&amp;quot;%d&amp;quot;, &amp;amp;age); // 让用户输入数字存到盒子里 printf(&amp;quot;你明年的年龄是:%d岁&amp;quot;, age+1); // 自动计算</code></pre> <p><strong>效果</strong>: </p> <pre><code>请输入你的年龄:18 你明年的年龄是:19岁 </code></pre> <h3>2. 条件判断(像选择题)</h3> <pre><code class="language-c">int score; printf(&amp;quot;输入考试分数:&amp;quot;); scanf(&amp;quot;%d&amp;quot;, &amp;amp;score); if(score &amp;gt;= 60) { printf(&amp;quot;及格!奖励鸡腿!\n&amp;quot;); } else { printf(&amp;quot;补考通知已发送家长群\n&amp;quot;); }</code></pre> <h3>3. 循环(自动重复劳动)</h3> <pre><code class="language-c">// 打印5次&amp;quot;正在加载...&amp;quot; for(int i=0; i&amp;lt;5; i++) { printf(&amp;quot;第%d次加载中...\n&amp;quot;, i+1); }</code></pre> <hr /> <h2>常见错误急救包</h2> <table> <thead> <tr> <th>错误现象</th> <th>解决办法</th> </tr> </thead> <tbody> <tr> <td>编译报错<code>error</code></td> <td>检查符号是否全英文,比如<code>;</code>改成<code>;</code></td> </tr> <tr> <td>运行完窗口闪退</td> <td>在代码最后加<code>system(&amp;quot;pause&amp;quot;);</code>(仅Windows)</td> </tr> <tr> <td>输入数字后没反应</td> <td><code>scanf</code>里的<code>&amp;amp;</code>别漏写,比如<code>&amp;amp;age</code></td> </tr> </tbody> </table> <hr /> <p><strong>下一步建议</strong>: </p> <ol> <li>把以上代码全部手敲一遍(复制会失去灵魂!) </li> <li>修改<code>printf</code>里的文字和数字,观察变化 </li> <li>参考<a href="https://www.runoob.com/cprogramming">菜鸟教程C语言版</a> 玩更多案例 </li> </ol> <p>&gt; <strong>小白心法</strong>:编程就像搭积木,先模仿再创新。所有错误都是升级提示,看到报错=系统在教你!</p>

页面列表

ITEM_HTML