GESP二级(三) - ZHI-BLOG
LaTeX Rendering with MathJax
侧边栏壁纸

GESP二级(三)

2024年09月01日 89阅读 1评论 3点赞
s

质数判断

质数:除了1和它本身没有其他因数的数

    int n , num = 0;
    cin >> n;
    /*一*/
    for (int i = 1; i <= n; i++)
    {
        if (n % i == 0)
        {
            num++;
        }
    }
    if (num > 2)
    {
        cout << "质数";
    }
    else
    {
        cout << "合数";
    }

    int n;
    bool b = 1;//默认是一个质数
    for (int i = 2; i < n; i++)
    {
        if (n % i == 0)
        {
            b = 0;
            break;
        }
    }
    if (b)
    {
        cout << "y";
    }
    else
    {
        cout << "n";
    }

数位拆分

    int n;
    cin >> n;
    while (n)
    {
        cout << n % 10;//输出个位
        n /= 10;//扔掉个位
    }

图案循环嵌套

(打印一个由“*”组成的 6x7的长方形)

    for (int i = 1; i <= 6; i++)
    {
        for (int j = 1; j <= 7; j++)
        {
            cout << "*";
        }
        cout << endl;
    }

最大值

max(a,max(b,max(c,d)))

最小值

min(a,min(b,min(c,d)))
3
打赏

—— 评论区 ——

昵称
邮箱
网址
取消
  1. @
    头像
    刘郎
    GNU/Linux x64 GNU/Linux x64   Google Chrome 127 Google Chrome 127

    这笔记做的 👍

博主栏壁纸
53 文章数
65 标签数
42 评论量
人生倒计时
舔狗日记