内容大纲

约 205 字小于 1 分钟

2024-02-10

水仙花数

获取从100-1000之间的水仙花

#include <stdio.h>

int main()
{
    for (int i = 100; i < 1000; i++)
    {
        if (check(i))
        {
            printf("%d\n", i);
        }
    }
}

int check(int number)
{
    int first = number / 100;
    int second = number / 10 % 10;;
    int third = number % 10;
    return first * first * first + second * second * second + third * third * third == number;
}

九九乘法表

#include <stdio.h>

int main()
{
    for (int i = 1; i <= 9; i++)
    {
        for (int j = 1; j <= i; j++)
        {
            printf("%d x %d = %-2d ", i, j, i * j);
        }

        printf("\n");
    }
}

斐波那契数列

规则

当前数为 n

(n-2)+(n-1)=n 时,这个数为 斐波那契数列

要求

传入需要获取的第几个

#include <stdio.h>

int main()
{
    int target = 7;
    int result = 0;

    int a = 1, b = 1, c = 0;
    for (int i = 2; i < target; i++)
    {
        c = a + b;
        a = b;
        b = c;
    }

    result = c;

    printf("%d 个数为 %d", target, result);
}