[英]Why is this simple C program not showing any output?
I have to count how many times the loop runs for a given input, I am trying to use a custom value for n
to come up with a formula but the following dummy program does not show any output nor does it show any error.我必须计算循环针对给定输入运行的次数,我试图使用
n
的自定义值来提出公式,但以下虚拟程序不显示任何输出,也不显示任何错误。 There are custom values of n
which vary as 4^k
and I have used a random value 64
to see how many times the loop runs. n
自定义值随4^k
变化,我使用了随机值64
来查看循环运行了多少次。
I have tried to include the printf()
statement in the while loop itself to see if the compiler even enters that loop or not but I still am not getting any result.我试图在 while 循环本身中包含
printf()
语句,以查看编译器是否甚至进入该循环,但我仍然没有得到任何结果。 I haven't done much programming in C and I am running the program in an online compiler.我没有用 C 做过很多编程,我在一个在线编译器中运行程序。
int main()
{
int i;
int j;
int n=64;
int count=0;
for(i=1;i<=n;i++){
j = 2;
while(j<=n){
j = i*i;
count +=1 ;
}
}
printf("%d",count);
return 0;
}
First loop, going into the while
loop.第一个循环,进入
while
循环。 We assign我们分配
j = 2
Then, while j
is less than 64, we assign然后,当
j
小于 64 时,我们分配
j = 1 * 1
Now we reset the while loop, but i
is unchanged, so we do again现在我们重置 while 循环,但
i
没有改变,所以我们再做一次
j = 1 * 1
So this is an infinite while loop that never completes.所以这是一个永远不会完成的无限while循环。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.