- C 標準庫
- C 庫 - 首頁
- C 庫 - <assert.h>
- C 庫 - <complex.h>
- C 庫 - <ctype.h>
- C 庫 - <errno.h>
- C 庫 - <fenv.h>
- C 庫 - <float.h>
- C 庫 - <inttypes.h>
- C 庫 - <iso646.h>
- C 庫 - <limits.h>
- C 庫 - <locale.h>
- C 庫 - <math.h>
- C 庫 - <setjmp.h>
- C 庫 - <signal.h>
- C 庫 - <stdalign.h>
- C 庫 - <stdarg.h>
- C 庫 - <stdbool.h>
- C 庫 - <stddef.h>
- C 庫 - <stdio.h>
- C 庫 - <stdlib.h>
- C 庫 - <string.h>
- C 庫 - <tgmath.h>
- C 庫 - <time.h>
- C 庫 - <wctype.h>
- C 標準庫資源
- C 庫 - 快速指南
- C 庫 - 有用資源
- C 庫 - 討論
- C 程式設計資源
- C 程式設計 - 教程
- C - 有用資源
C 庫 - csin() 函式
C 的複數庫 csin() 函式計算給定複數的複數正弦。此函式在 <complex.h> 標頭檔案中定義。
語法
以下是 csin() 函式的 C 庫語法:
double complex csin(double complex z);
引數
此函式只接受一個引數 (z),該引數定義複數。
返回值
函式返回型別為雙精度複數。如果沒有錯誤發生,則返回 z 的複數正弦。
示例 1
以下是 C 庫程式,它使用 csin() 函式來說明常數值的複數正弦。
#include <stdio.h>
#include <complex.h>
int main() {
double complex z = 1 + 2 * I;
double complex result = csin(z);
printf("sin(1 + 2i) = %.3f + %.3fi\n", creal(result), cimag(result));
return 0;
}
輸出
執行上述程式碼後,我們將得到以下結果:
sin(1 + 2i) = 3.166 + 1.960i
示例 2
在這裡,我們自定義了一個名為 custom_csin() 的函式,它接受角度值來確定正弦的任務(使用者提供的角度以弧度表示)。
#include <stdio.h>
#include <math.h>
#include <complex.h>
double complex custom_csin(double angle) {
// Implement your custom complex sine calculation here
return csin(angle);
}
int main() {
double angle = 0.5;
double complex res = custom_csin(angle);
printf("Custom sin(%.3f) = %.3f + %.3fi\n", angle, creal(res), cimag(res));
return 0;
}
輸出
執行上述程式碼後,我們將得到以下結果:
Custom sin(0.500) = 0.479 + 0.000i
示例 3
下面的示例演示了虛數值的複數正弦。在這裡,我們觀察當輸入為純虛數時 csin() 的行為。
#include <stdio.h>
#include <complex.h>
int main() {
double y_values[] = { 1.0, 2.0, 3.0 };
for (int i = 0; i < 3; ++i) {
double complex p = I * y_values[i];
double complex res = csin(p);
printf("sin(i%.1f) = %.3f + %.3fi\n", y_values[i], creal(res), cimag(res));
}
return 0;
}
輸出
上述程式碼產生以下結果:
sin(i1.0) = 0.000 + 1.175i sin(i2.0) = 0.000 + 3.627i sin(i3.0) = 0.000 + 10.018i
c_library_complex_h.htm
廣告