LeetCode 537. Complex Number Multiplication

1
2
3
4
5
6
7
8
9
10
11
char* complexNumberMultiply(char* a, char* b) {
    int a1,a2,b1,b2;
    sscanf(a, "%d+%di", &a1,&a2);
    sscanf(b, "%d+%di", &b1,&b2);
    int c1=a1*b1-a2*b2;
    int c2=a1*b2+a2*b1;
    char* ret=(char*)malloc(sizeof(int)*80);
    memset(ret, '\0', sizeof(int)*80);
    sprintf(ret, "%d+%di",c1,c2);
    return ret;
}



Leave a Reply

Your email address will not be published. Required fields are marked *