Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 在没有循环的情况下,如何计算“命中率”?_C_Loops_Mod - Fatal编程技术网

C 在没有循环的情况下,如何计算“命中率”?

C 在没有循环的情况下,如何计算“命中率”?,c,loops,mod,C,Loops,Mod,这不是编程问题,我没有这样的代码。但我对处理这类问题的数学方法感兴趣。 printf返回96次点击 我的问题是,有没有一个公式可以计算不带循环的“命中率”?这篇文章: #include <stdio.h> int main() { int ix; unsigned hits = 0; for (ix=0; ix < 128; ix++) { if (ix % 4 == 0) continue;

这不是编程问题,我没有这样的代码。但我对处理这类问题的数学方法感兴趣。 printf返回96次点击 我的问题是,有没有一个公式可以计算不带循环的“命中率”?

这篇文章:

#include <stdio.h>

int main()
{
    int ix;
    unsigned hits = 0;
    for (ix=0; ix < 128; ix++)
    {   
        if (ix % 4 == 0)
            continue;   

        hits++;
    }
    printf("%u hits\n", hits);
    return;
}
基本上意味着每四次迭代跳过一次。这意味着它与减少25%的迭代次数相同。因此在本例中,由于操作hits++完全不依赖于值ix,因此整个过程与以下内容相同:

if (ix % 4 == 0)
    continue;   

hits=128*0.75或hits=128*3/4,如果您不想增加浮点的开销。
unsigned hits = 0;
for (ix=0; ix < 128 * 3/4; ix++)
{   
    hits++;
}
hits = 128*3/4;