c code for the roots of x to the power of 3 plus 1?

回答: ChatGPT被方程x^3+1=0卡住了時不時來看看2023-02-12 12:58:40

#include <complex.h>
#include <math.h>
#include <stdio.h>

int main() {
    double complex root1, root2, root3;
    root1 = cbrt(-1) * cexp(I * M_PI / 3);
    root2 = cbrt(-1) * cexp(I * (2 * M_PI / 3));
    root3 = cbrt(-1) * cexp(I * (4 * M_PI / 3));
    printf("root 1: %.2f + %.2fi\n", creal(root1), cimag(root1));
    printf("root 2: %.2f + %.2fi\n", creal(root2), cimag(root2));
    printf("root 3: %.2f + %.2fi\n", creal(root3), cimag(root3));
    return 0;
}

所有跟帖: 

請您先登陸,再發跟帖!