公式:
结果 | 计算 | 结果 | 计算 |
注:dBm与dB不是简单地移动三位小数点
结果与在线计算器对比:
在线计算器计算结果
(链接:分贝在线计算器 - 在线计算网 (zaixianjisuan.com))
程序运行结果
程序:
dB
#include <stdio.h>
#include <math.h>
//https://blog.csdn.net/qq_32752869/article/details/79864748
int main() {
double base = 10; // 设置底数为10
double exponent = -100; // 设置指数为3
while(1)
{
printf("输入dB:");
scanf("%lf",&exponent);
printf("%lfdB:",exponent);
exponent = exponent/20.0;
printf("结果为:%lf V 或 %lf mV\n", pow(base, exponent),1000*pow(base, exponent)); // 使用printf函数打印pow的返回值
}
return 0;
}
dBm
#include <stdio.h>
#include <math.h>
int main() {
double base = 10; // 设置底数为10
double exponent = -100; // 设置指数为3
while(1)
{
printf("输入dBm:");
scanf("%lf",&exponent);
printf("%lfdBm:",exponent);
exponent = exponent/20.0;
printf("结果为:%lf mV 或 %lf V\n", pow(base, exponent),pow(base, exponent)/1000); // 使用printf函数打印pow的返回值
}
scanf("%lf",&exponent);
return 0;
}