本文介绍了我不知道这个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! #include< stdio.h> #include< conio.h> main() { int n; while(1< = n< = 100) { printf("%d", n); } } 现在这段代码可以无限地输出783 ......如果数字 介于1到100之间,然后它应该是无印刷的,否则它根本不应该打印 ///为什么会发生这种情况???#include<stdio.h>#include<conio.h>main(){int n;while(1<=n<=100){printf("%d ",n);}}Now this code prints something like 783 infinitely.....if the numberis between 1 to 100 then it should be printed infinetely else itshould not be printed at all///why is it so happening???推荐答案 n未初始化(因此它可以是任何东西,包括783) " 1< = n< = 100"并不意味着n在1和100之间。而是像 "(1小于或等于n)小或等于100这是永远的 是的,因为表达式(1小于或等于n)的任何结果 将小于或等于100(它将是1或0) 因此它将继续打印n,永远,n在功能上是随机的,并且 不会改变。 你可能想试试 #include< stdio.h> #include< conio.h> main( ) { int n; while(n< =&& n> 0) { printf("%d",n); } } 它仍然没有意义,但至少条件会做你的意思n is not initialized (so it could be anything, including 783)"1<=n<=100" does Not mean "n is between 1 and 100" but rather something like"(1 is smaller or equal to n) is small or equal to 100" which is allwaysTrue because any outcome of the expression "(1 is smaller or equal to n)"will be smaller or equal to 100 (it will be either 1 or 0)Therefore it will keep printing n, forever, n is functionally random andwill not change.you may want to try#include<stdio.h>#include<conio.h>main(){int n;while(n<=100 && n>0){printf("%d ",n);}}it will still not make sense but atleast the condition will do what you mean n未初始化(因此它可能是任何东西,包括783) " 1< = n< = 100"并不意味着n在1和100之间。而是像 之类的(1小于或等于n)小或等于100。这是 总是正确的,因为表达式的任何结果(1小于或等于 到n)将小于或等于100(它将是1或0)n is not initialized (so it could be anything, including 783)"1<=n<=100" does Not mean "n is between 1 and 100" but rather somethinglike "(1 is smaller or equal to n) is small or equal to 100" which isallways True because any outcome of the expression "(1 is smaller or equalto n)" will be smaller or equal to 100 (it will be either 1 or 0) 实际上,对于True,允许除0以外的任何值,但至少 与您的编译器True最终小于等于100(可能是 42或-1或-666但是)actually, for True any value other than 0 would be allowed, but at leastwith your compiler True ends up being smaller of equal to 100 (it could be42 or -1 or -666 however) n未初始化(因此它可能是任何东西,包括783) " 1< = n< = 100"并不意味着n在1和100之间。而是像 "(1小于或等于n)小或等于100这是永远的 是的,因为表达式(1小于或等于n)的任何结果 将小于或等于100(它将是1或0) 因此它将继续打印n,永远,n在功能上是随机的,并且 不会改变。 你可能想试试 #include< stdio.h> #include< conio.h> main( ) { * * int n; * * while(n * * { * * * printf("%d",n); * *} }n is not initialized (so it could be anything, including 783)"1<=n<=100" does Not mean "n is between 1 and 100" but rather something like"(1 is smaller or equal to n) is small or equal to 100" which is allwaysTrue because any outcome of the expression "(1 is smaller or equal to n)"will be smaller or equal to 100 (it will be either 1 or 0)Therefore it will keep printing n, forever, n is functionally random andwill not change.you may want to try#include<stdio.h>#include<conio.h>main(){* *int n;* *while(n<=100 && n>0)* *{* * * printf("%d ",n);* *}} 这里也会无限打印或不打印 任何东西。 看,n根本没有改变。 所以真的需要检查程序的目的 - vIpInHere also, it will print either infinitely or will not printanything.see, n is not being changed at all.so really need to check the purpose of program--vIpIn 这篇关于我不知道这个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!