Multiplication of very long integers

后端 未结 7 1001
耶瑟儿~
耶瑟儿~ 2021-02-09 06:04

Is there an algorithm for accurately multiplying two arbitrarily long integers together? The language I am working with is limited to 64-bit unsigned integer length (maximum int

7条回答
  •  北海茫月
    2021-02-09 06:31

    Here is my code piece in C. Good old multiply method

    char *multiply(char s1[], char s2[]) {
        int l1 = strlen(s1);
        int l2 = strlen(s2);
        int i, j, k = 0, c = 0;
        char *r = (char *) malloc (l1+l2+1); // add one byte for the zero terminating string
        int temp;
    
        strrev(s1);
        strrev(s2);
        for (i = 0;i 

提交回复
热议问题