• º» °Ô½ÃÆÇÀº ¼ö¾÷½Ã°£¿¡ Çлýµé ½Ç½ÀÀ» À§ÇÑ °Ô½ÃÆÇÀÔ´Ï´Ù.
  • º» °Ô½ÃÆÇ¿¡ ¿Ã¶ó¿Í ÀÖ´Â ÇÁ·Î±×·¥Àº ´ëºÎºÐ ¿Ã¹Ù¸£Áö ¾ÊÀº ÇÁ·Î±×·¥ÀÔ´Ï´Ù.
        À±Çü½Ä
        ddd



    #include <stdio.h>

    #include <stdlib.h>

     

    struct Stack {

        int capacity;

        int top;

        int* array;

    };

     

     

    struct Stack* createStack(unsigned capacity) {

        struct Stack* stack = (struct Stack*)malloc(sizeof(struct Stack));

        stack->capacity = capacity;

        stack->top = -1;

        stack->array = (int*)malloc(stack->capacity * sizeof(int));

        return stack;

    }

     

     

    int isEmpty(struct Stack* stack) {

        return stack->top == -1;

    }

     

     

    int isFull(struct Stack* stack) {

        return stack->top == stack->capacity - 1;

    }

     

     

    void push(struct Stack* stack, int item) {

        if (isFull(stack)) {

            return;

        }

        stack->array[++stack->top] = item;

    }

     

     

    int pop(struct Stack* stack) {

        if (isEmpty(stack)) {

            return -1;

        }

        return stack->array[stack->top--];

    }

     

    long long int factorial(int n) {

        if (n <= 1) {

            return 1;

        }

     

        struct Stack* stack = createStack(n);

        long long int result = 1;

     

        while (n > 1) {

            push(stack, n);

            n--;

        }

     

        while (!isEmpty(stack)) {

            result *= pop(stack);

        }

     

        free(stack);

        return result;

    }

     

    int main(void) {

        int num;

        printf("insert num: ");

        scanf("%d", &num);

     

        if (num < 0) {

            printf("negative cant be calculated.\n");

        } else {

            long long int result = factorial(num);

            printf("factorial(%d): %lld\n", num, result);

        }

     

        return 0;

    }

     

      µî·ÏÀÏ : 2023-10-31 [14:43] Á¶È¸ : 172 ´Ù¿î : 0   
     
    ¡â ÀÌÀü±ÛµµÀü¹®Á¦
    ¡ä ´ÙÀ½±Û¾ß±¸°ÔÀÓ
    Çлý½Ç½À °Ô½ÃÆÇ
    ¹øÈ£ ¨Ï Á¦ ¸ñ À̸§ Á¶È¸ µî·ÏÀÏ
    97 Å¥¸¦ ÀÌ¿ëÇÑ ³Êºñ ¿ì¼± Ž»ö ÇÁ·Î±×·¡¹Ö¾ð¾î ÀÓÀç¸ð 1 10-29
    96 Å¥¸¦ ÀÌ¿ëÇÑ ³Êºñ ¿ì¼± Ž»ö BFS ±¸Çö ÀڷᱸÁ¶ À̱âÁ¤ 14 10-29
    95 Á¶°Ç¹® µµÀü°úÁ¦1 ÇÁ·Î±×·¡¹Ö¾ð¾î ÃÖÇö¿ì 64 04-12
    94 4¿ù12ÀÏ ¼¼¼ö ºñ±³ ½Ç½À ÇÁ·Î±×·¡¹Ö¾ð¾î À±¿µ¹Î 77 04-12
    93 µµÀü¹®Á¦ ÇÁ·Î±×·¡¹Ö¾ð¾î ÀÌÀ±È¯ 73 04-12
    92 asdff ºñ°ø°³ ÇÁ·Î±×·¡¹Ö¾ð¾î À±Çü½Ä 133 11-28
    91 ¾ß±¸°ÔÀÓ ÇÁ·Î±×·¡¹Ö¾ð¾î À±Çü½Ä 134 11-28
    90 ddd ÇÁ·Î±×·¡¹Ö¾ð¾î À±Çü½Ä 172 10-31
    89 ½Ç½À2 ÇÁ·Î±×·¡¹Ö¾ð¾î ¼­¼ºÀº 523 03-16
    88 ¦¦❶ ½Ç½À2 ÇÁ·Î±×·¡¹Ö¾ð¾î Á¤¼ºÈÆ 457 03-16
    87 ¾ß±¸ ÇÁ·Î±×·¡¹Ö¾ð¾î ¹éÇö¹Î 689 10-31
    86 °Å²Ù·Î ÇÁ·Î±×·¡¹Ö¾ð¾î ±è°æȸ 723 09-26
    85 ¤±¤¤¤· ÇÁ·Î±×·¡¹Ö¾ð¾î Á¶¹®±Ù 849 06-13
    84 ·Î¶Ç ÇÁ·Î±×·¡¹Ö¾ð¾î ±è»ó¿ì 860 05-30
    83 ÇÔ¼ö ÇÁ·Î±×·¡¹Ö¾ð¾î ±è°æȸ 944 05-23

    [1][2][3][4][5][6][7]