比较运算符comparision operators

OperatorNameExample
==等于 Equal tox == y
!=不等于Not equalx != y
>大于Greater thanx > y
<< Less thanx < y
>=大于等于Greater than or equal tox >= y
<=小于等于Less than or equal tox <= y
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#include <iostream>
using namespace std;


int main()
{
    int a;
    cout<<"please input a number:";
    cin>>a;
    if(a==10)cout<<"I am equal to ten"<<endl;
    if(a!=10)cout<<"I am not equal to ten"<<endl;
    if(a>10)cout<<"I am greater than ten"<<endl;
    if(a<10)cout<<"I am less than tem"<<endl;
    if(a>=10)cout<<"I am Greater than or equal to ten"<<endl;
    if(a<=10)cout<<"I am Less than or equal to ten"<<endl;

    return 0;
}
Scroll to Top