修改密码

【2024课程】零基础学会C++编程课程

成品课程

陈远龙老师主讲 & 答疑

课程题单 - T1000

未购买 · 可先试学25节课

课程目录展开/折叠

第9课 C++中的运算符

播放快捷键

播放/暂停:空格(或鼠标单击)      全屏:F(或鼠标双击)      退出全屏:Esc

快进10 / 30 / 60秒:方向键→ / Ctrl + 方向键→ / Shift + 方向键→

快退10 / 30 / 60秒:方向键← / Ctrl + 方向键← / Shift + 方向键←

本节课讲解配套PPT&板书:

本节课讲解到的源代码

源代码下载:第9课 C++中的运算符-源代码下载

1. P1040-奇偶数判断
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;

    if (n % 2 == 0) // 偶数 
    {
        cout << "even"; // 'even'是错误的 
    }
    else
    {
        cout << "odd";
    }

    return 0;
} 
2. P1040-奇偶数判断-2
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;

    if (n % 2) // 0 =>假 非0 => 真 
    {
        cout << "odd"; // 奇数 
    }
    else
    {
        cout << "even"; // 偶数 
    }

    return 0;
} 
3. P1041-分离三位正整数各位上的数
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n; 
    cin >> n;

    int bw = n / 100; // 百位
    int sw = n / 10 % 10; // 十位 
    int gw = n % 10; // 个位 

    cout << bw << ' ' << sw << ' ' << gw;

    return 0;
}
4. P1041-分离三位正整数各位上的数-2
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n; 
    cin >> n;

    int bw = n / 100; // 百位
    // int sw = n / 10 % 10; // 十位 
    // int sw = (n - bw * 100) / 10;
    int sw = n % 100 / 10;
    int gw = n % 10; // 个位 

    cout << bw << ' ' << sw << ' ' << gw;

    return 0;
}
5. P1042-反向组成一个三位正整数
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int bw = n / 100; // 百位 
    int sw = n / 10 % 10; // 十位 
    int gw = n % 10; // 个位

    // ans => answer 答案 res(ret) => result 结果 tot idx
    int ans = gw * 100 + sw * 10 + bw * 1; 
    cout << ans;

    return 0;
}
6. P1042-反向组成一个三位正整数-2
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int bw = n / 100; // 百位 
    int sw = n / 10 % 10; // 十位 
    int gw = n % 10; // 个位

    // cout << gw << sw << bw;
    if (gw != 0)
        cout << gw;
    /* 
    if (sw != 0)
        cout << sw;
    */
    if (gw != 0)
        cout << sw;
    if (gw == 0 && sw != 0)
        cout << sw;

    cout << bw;

    return 0;
}
7. P1043-计算表达式的值-1
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    double ans = 1.0 / 2 + (double)(a - b) / (a + b);
    cout << fixed << setprecision(2) << ans;

    return 0;
}
8. P1043-计算表达式的值-2
#include <bits/stdc++.h>
using namespace std;

int main()
{
    double a, b;
    cin >> a >> b;
    double ans = 1.0 / 2 + (a - b) / (a + b);
    cout << fixed << setprecision(2) << ans;

    return 0;
}
9. P1043-计算表达式的值-3
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    double ans = (double)1 / 2 + (a * 1.0 - b) / (a + b);
    cout << fixed << setprecision(2) << ans;

    return 0;
}

本节课答疑

建议大家有问题先通过AI答疑(比如:DeepSeek 等),AI时代需要学会使用AI辅助学习

陈远龙老师视频讲解:如何使用DeepSeek进行答疑?

通过AI未能获得满意解答的,可以联系陈远龙老师答疑

目录