强制输入大于或等于 0 且小于 24
Enforce input greater than or equal to 0 and less than 24
#include<stdio.h>
int main ()
{
int n,a=0,b=24;
do
{
scanf("%d",n); //ask the user to enter a value of n less than 24
// but greater than 0.
} while(/*boolean expression logic*/)
if(a<n<b)
{
printf("%d\n",n);
}
return 0;
}
我要评价:
If the value of n is greater than or equal to 0 and less than 24 (less than or equal to 23) then
.... go to the if statement and print the value of n
otherwise
... ask the user to input the value of n i.e. it should again go back in the loop.
您希望程序一直询问值直到 n>=0 && n<24
;换句话说,你想在 !(n>=0 && n<24)
时继续求值,使用 De Morgan's law 我们可以写成 !(n>=0) || !(n<24)
,可以简化为 n<0 || n>=24
do
{
scanf("%d",n);
}
while(n<0 || n>=24)
#include<stdio.h>
int main ()
{
int n,a=0,b=24;
do
{
scanf("%d",n); //ask the user to enter a value of n less than 24
// but greater than 0.
} while(/*boolean expression logic*/)
if(a<n<b)
{
printf("%d\n",n);
}
return 0;
}
我要评价:
If the value of n is greater than or equal to 0 and less than 24 (less than or equal to 23) then
.... go to the if statement and print the value of n
otherwise
... ask the user to input the value of n i.e. it should again go back in the loop.
您希望程序一直询问值直到 n>=0 && n<24
;换句话说,你想在 !(n>=0 && n<24)
时继续求值,使用 De Morgan's law 我们可以写成 !(n>=0) || !(n<24)
,可以简化为 n<0 || n>=24
do
{
scanf("%d",n);
}
while(n<0 || n>=24)