运行此代码时,我没有得到任何 lambda 值,它始终为 0

While running this code I'm not getting any lambda value, it isd always 0

提问人:Ravi Kumar Verma 提问时间:10/17/2023 最后编辑:JabberwockyRavi Kumar Verma 更新时间:10/18/2023 访问量:70

问:

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

int main(){
    double f,n,xm,sum=0;    
    const double PI = 3.14159;
    
    printf("Enter the Value of 'f'(CM) : ");
    
    scanf("%lf",&f);
    
    for (double i = 1; i < 8; i++)
    {
       printf("\nEnter the Value of 2Xm(cm) : ");        
       scanf("%lf",&n);        
       xm = (n/2);
    
       printf("%lf",i);
    
       double theta = atan(xm/f);        
       double theta_m = theta * ( 180.0 / PI );        
       double sine_theta = sin(theta);                
       double lambda = (0.0000508*sine_theta)/(i);
    
    
       printf("\nXm : %.2lf",xm);        
       printf("\nTheta : %.4lf",theta_m);        
       printf("\nSine Theta(m) : %.4lf",sine_theta);
       printf("\nlambda : %.4lf",lambda);
       printf("");
       sum+=lambda;        
    }
    
    return 0;   
}

使用以下值:

  • f = 85
  • xm = 2.2、4.4、6.7 或 9

“f = 2.2”的 lambda 值应约为 6.5532e-07,6.7 = 6.671733333333333e-07,依此类推。

但它每次都显示 0。

c 数学

评论

3赞 pmg 10/17/2023
6.5532e-07是。尝试其他格式: 或0.00000065532"%g""%.12f"
3赞 BoP 10/17/2023
%.4f会打印 4 位小数,对吧?当前 6 位小数为零时会发生什么?
0赞 Bob__ 10/18/2023
OT:考虑使用 atan2(xm, f) 而不是 .atan(xm/f)
0赞 n. m. could be an AI 10/18/2023
@Bob__不“考虑”。只是“使用”。 总是错的。atan(x/y)

答:

0赞 Ahmed Ehab 10/18/2023 #1

只需提高双变量 lambda 的 printf 精度即可。

printf("\nlambda : %.12lf",lambda);

使用低于 6 的精度只会显示零,因为 Lambda 在您的示例中< 1e-6。