【题目链接】
ybt 1044:判断是否为两位数
OpenJudge NOI 1.4 06:判断是否为两位数
【题目考点】
1. 逻辑运算符:与&&
逻辑表达式a && b
,
- a与b的值都是true时,整个表达式的值是true。
- a或b的值为false时,整个表达式的值为false
例:判断数x是否满足 a < = x < = b a <= x <= b a<=x<=b:x >= a && x <= b
2. if…else语句嵌套
3. 输出布尔型量
- 若布尔型量的值为true,会输出1
- 若布尔型量的值为false,会输出0。
【题解代码】
解法1:使用逻辑表达式
#include<bits/stdc++.h>
using namespace std;
int main()
{
int x;
cin>>x;
if(x >= 10 && x <= 99)
cout<<1;
else
cout<<0;
return 0;
}
解法2:直接输出逻辑表达式
#include<bits/stdc++.h>
using namespace std;
int main()
{
int x;
cin>>x;
cout<<(x >= 10 && x <= 99);
return 0;
}
解法3:嵌套if…else
#include<bits/stdc++.h>
using namespace std;
int main()
{
int x;
cin>>x;
if(x >= 10)
{
if(x <= 99)
cout<<1;
else
cout<<0;
}
else
cout<<0;
return 0;
}