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

來源: psp2000 2023-02-12 13:26:57 [] [舊帖] [給我悄悄話] 本文已被閱讀: 次 (689 bytes)
回答: 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;
}

所有跟帖: 

試了 c, pascal, matlab, lisp等編程語言,書寫還是比較規範的,哈哈。 -psp2000- 給 psp2000 發送悄悄話 (0 bytes) () 02/12/2023 postreply 13:54:00

請您先登陸,再發跟帖!

發現Adblock插件

如要繼續瀏覽
請支持本站 請務必在本站關閉/移除任何Adblock

關閉Adblock後 請點擊

請參考如何關閉Adblock/Adblock plus

安裝Adblock plus用戶請點擊瀏覽器圖標
選擇“Disable on www.wenxuecity.com”

安裝Adblock用戶請點擊圖標
選擇“don't run on pages on this domain”