① 如何用c語言實現求一個復數的自然對數
#include<stdio.h>
#include<math.h>
void main()
{
double a, b, x, y;
printf("請輸入復數的實數部分:\t");
scanf("%lf", &x);
printf("請輸入復數的虛數部分:\t");
scanf("%lf", &y);
b = atan2(y, x);
a = log(x * x + y * y) /2;
printf("它的自然對數是:\t%f + i%f\n", a, b);
}
② C語言中,自然對數是怎樣表示的舉個例子
C語言中直接提供的是e為底的自然對數log,和以10為底的常用對數log10,其他對數寫個函內數就可以。
#include <stdio.h>
#include <math.h>
double loga(double n, double base);
int main (void)
{
double a, b, c;
a = log(exp(1));
b = log10(10);
c = loga(100, 5);
printf("%lf %lf %lf", a, b, c);
}
double loga(double n, double base)
{ return log(n) / log(base);}
(2)c語言自然對數怎麼求擴展閱讀:
如果一個變數名後面跟著一個有數字的中括弧,這個聲明就是數組聲明。字元串也是一種數組。它們以ASCII的NULL作為數組的結束。要特別注意的是,中括弧內的索引值是從0算起的。
C語言的字元串其實就是以'