Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/72.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 - Fatal编程技术网

代码打印什么?C语言练习

代码打印什么?C语言练习,c,C,我不知道为什么这个代码打印的是“h=13”而不是“h=2”。有人有主意吗 #include <stdio.h> int main() { int j,h=1; for(j=0;j<50;j++) { if(j%6==1) continue; h++; if(j==7 || j==14 || j==21) break; } printf("h=%d",h); return 0; } #包括 int

我不知道为什么这个代码打印的是“h=13”而不是“h=2”。有人有主意吗

#include <stdio.h>

int main() {
int j,h=1;
for(j=0;j<50;j++) {
        if(j%6==1) continue;
        h++;
        if(j==7 || j==14 || j==21)
               break;
}
printf("h=%d",h);
return 0;
}
#包括
int main(){
int j,h=1;
对于(j=0;j
  • j=0
    时,两个if语句都不返回值1,因此
    h
    递增
  • 中的
    j=1
    (j%6==1)
    时,1%6将给出1的余数。语句
    j%6
    为真,因此h不会递增。(“%”是余数运算符)
  • j=2
    j=6
    时,两条if语句都不返回值1,因此
    h
    递增
  • 中的
    j=7
    时(j%6==1)
    7%6将给出1的余数。语句
    j%6
    为真,因此h不会增加
  • j=8
    j=12
    时,两个if语句都不返回值1,因此
    h
    递增
  • 中的
    j=13
    时(j%6==1)
    13%6将给出1的余数。语句
    j%6
    为真,因此h不会增加
  • 对于
    j=14
    ,语句
    j==14为
    true,因此执行break语句
  • h将为:
    j
    =0,
    j
    =2到
    j
    =6,
    j
    =8到
    j
    =12,
    j
    =14,共12次


    总共12+1(
    h=1
    )=13

    自己试试。如果没有编译器,请使用联机编译器。使用断点逐行进行提示:表达式
    j%6
    j
    为7时的计算结果是什么?想想
    j=7
    时会发生什么,想想
    continue
    的意思是什么,而不是“h=2”“.h=2有什么特别之处?为什么这个代码会打印h=2?”?