- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
这是我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
FILE *infile, *outfile;
int main(){
double landa, mu, lo, blocking_prob[4], mean_arrival_rate,
mean_service_rate, k[4], p[4];
infile = fopen("mm1.in", "r");
outfile = fopen("mm1.out", "w");
fscanf(infile, "%d %d %d %d %d %d",
&mean_arrival_rate, &mean_service_rate,
&k[0],&k[1],&k[2],&k[3] );
lo = mean_arrival_rate / mean_service_rate;
fprintf(outfile,
"Initial setting : mean_arrival_rate = %d , mean_service_rate = %d \n\n",
mean_arrival_rate,mean_service_rate);
for(int x=0;x<4;x++) {
printf("%f \n",pow(lo,k[x]) );
blocking_prob[x]= ( (1-lo)*pow(lo,k[x]) ) / (1- pow(lo,k[x]+1));
fprintf(outfile,"Blocking Probability is %f when K = %d \n\n",
blocking_prob[x],k[x]);
}
}
输出从pow(lo,k[x])开始,它输出了错误的数字。
我尝试将 k[] 替换为 const(例如 pow(lo,5)),结果是正确的。
有什么解决办法吗?
最佳答案
%d
不是 double 的正确 scanf
格式说明符。您需要使用 %lf
而不是 1。
如果您在读入后打印出 k[]
的值,您会发现它们与您的预期有很大不同。
例如,考虑以下程序:
#include <stdio.h>
int main (void) {
double d1, d2;
printf ("> ");
scanf ("%lf %d", &d1, &d2); // one right, one wrong.
printf ("Input was: %f %f\n", d1, d2);
return 0;
}
运行给你:
pax$ ./testprog
> 3.14159 2.71828
Input was: 3.141590 -0.000000
1 C11 7.21.6.2 fscanf 函数/10
说得最好:
If [the object receiving the value] does not have an appropriate type, or if the result of the conversion cannot be represented in the object, the behavior is undefined
关于c - 在 pow() 中执行双数组时输出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29531161/
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 9 年前。 Improv
我发现了 pow(x, n) 的迭代实现,它需要 o(log n) 时间和常量空间,如下所示: double pow(double x, int n) { double left = x;
我想创建一个特征,说它实现了num_traits::pow::Pow - Rust。 我的特征当前定义为: pub trait PrimeSieveTrait: AddAssign + MulAs
对于我的项目,我应该在 java 中创建一个图形计算器(绘制图形),并以函数作为输入。我已经找到了一种正确绘制函数图的方法。但是我想不出一种方法可以让解释器理解该功能。如果我能够做到这一点,以便我可以
我发现对于大整数,math.pow() 没有成功给出它的整数版本。 (我在使用 math.pow 实现时遇到了一个错误 Karatsuba multiplication)。 例如: >>> a_Siz
问题或多或少说明了一切。 calling a host function("std::pow ") from a __device__/__global__ function("_calc_psd")
我想知道,因为当我在检查模式下运行我的代码时,似乎出现了一些差异。例如: List getFactors(int n) { List factors = [[1, n]]; doubl
pow(a/b,x) 和 pow(b/a,-x) 在精度上有区别吗?如果存在,将小于 1 的数字提升为正幂或将大于 1 的数字提升为负幂会产生更准确的结果吗? 编辑:让我们假设 x86_64 处理器和
此代码在 Windows 上的 Visual Studio 2010 上正确编译,但我在 Linux、g++ 上遇到此错误。谁能解释一下如何解决这个问题? int bits; T scale; std
Python内置的pow(x, y)(没有第三个参数)返回的结果和math.pow()返回的值有区别吗>,在两个 float 参数的情况下。 我问这个问题是因为 documentation对于 mat
这个问题在这里已经有了答案: Why was std::pow(double, int) removed from C++11? (1 个回答) 关闭 9 年前。 在 C++ 03 中,使用例如st
我可以将pow()与#include 一起使用,而无需使用using关键字或::运算符。为什么? 最佳答案 来自标准的[headers]/4。 Except as noted in Clause 20
我觉得这很有趣: System.out.println( (long)(Math.pow(2,63) - 1) == Long.MAX_VALUE); // true System.out.prin
这个打印 100: int j=2; int i= pow(10,2); printf("%d\n", i); 这个打印出 99: int j=2; int i= pow(10,j); print
这也是一个与数学相关的问题,但我想用 C++ 实现它...所以,我有一个 2^n 形式的数字,我必须计算它的数字总和(以 10 为基数;P)。我的想法是用下面的公式来计算: sum = (2^n mo
我看到这个关于 std::pow 的老问题:What is more efficient? Using pow to square or just multiply it with itself? 旧
我正在尝试比较 pow(x,2.0) 和 pow(x,2.0000001) 的性能,但我认为 2.0 会快得多,但它们的速度相同。我什至通过使用 -Xint 参数运行 jar 来删除 JIT 优化。
我的 linux 版本是 4.19.0-6-amd64 #1 SMP Debian 4.19.67-2+deb10u1 (2019-09-20) x86_64 GNU/Linux我的 gcc 版本是
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 6 年前。 Improve t
python3 中的 pow() 函数提供指数的值。 >>>pow(2,3) 8 Python3 支持负指数,即 可以使用 pow(10,-1) 表示。当我计算 pow(4,-1,5) 时,它给出了输
我是一名优秀的程序员,十分优秀!