Relational Operators in C programming language return true(non-zero number) or false(0) value. They operate on 2 operands.
Relational Operators
== equality operator. != inequality operator. > greater than operator. < less than operator. >= greater than or equal to operator. <= less than or equal to operator.
#include < stdio.h >
int main()
{
//Relational Operators
int a = 10, b = 10;
int temp;
temp = (a == b);
printf("value of temp is %d\n", temp);
return 0;
}
#include < stdio.h >
int main()
{
//Relational Operators
int a = 10, b = 20;
int temp;
temp = (a == b);
printf("value of temp is %d\n", temp);
return 0;
}
#include < stdio.h >
int main()
{
//Relational Operators
int a = 10, b = 10;
int temp;
temp = (a != b);
printf("value of temp is %d\n", temp);
return 0;
}
#include < stdio.h >
int main()
{
//Relational Operators
int a = 10, b = 20;
int temp;
temp = (a != b);
printf("value of temp is %d\n", temp);
return 0;
}
#include < stdio.h >
int main()
{
//Relational Operators
int a = 20, b = 10;
int temp;
temp = (a > b);
printf("value of temp is %d\n", temp);
return 0;
}
#include < stdio.h >
int main()
{
//Relational Operators
int a = 20, b = 10;
int temp;
temp = (a < b);
printf("value of temp is %d\n", temp);
return 0;
}
#include < stdio.h >
int main()
{
//Relational Operators
int a = 20, b = 10;
int temp;
temp = (a >= b);
printf("value of temp is %d\n", temp);
return 0;
}
#include < stdio.h >
int main()
{
//Relational Operators
int a = 20, b = 10;
int temp;
temp = (a <= b);
printf("value of temp is %d\n", temp);
return 0;
}
Output: value of temp is 0
Scanf(): For user input
In above c program we are asking user to enter the values for variable a and b. You can know more about scanf() method/function in this video tutorial: Using Scanf in C Program
In this video tutorial we shall illustrate the use of comparison operators in MongoDB.
Comparison Operators $all $in $nin – not in $ne – not equal to $gt – greater than $gte – greater than or equal to $lt – less than $lte – less than or equal to
JavaScript file load.js – in path: C:/test/load.js
db.person.insert({
name : 'Satish',
age : 25,
skills : ['nodejs', 'mongoDB', 'HTML5']
});
db.person.insert({
name : 'Kiran',
age : 27,
skills : ['PHP', 'mySQL', 'HTML5']
});
db.person.insert({
name : 'Sunitha',
age : 24,
skills : ['html', 'ASP']
});
db.person.insert({
name : 'Jyothi',
age : 23,
skills : ['html', 'ASP']
});
db.person.insert({
name : 'Varsha',
age : 30,
skills : ['.NET', 'Java']
});
db.person.insert({
name : 'Amogh',
age : 29,
skills : ['C#', 'ASP']
});
db.person.insert({
name : 'Satish',
age : 25,
skills : ['nodejs', 'mongoDB', 'HTML5']
});
db.person.insert({
name : 'Kiran',
age : 27,
skills : ['PHP', 'mySQL', 'HTML5']
});
db.person.insert({
name : 'Sunitha',
age : 24,
skills : ['html', 'ASP']
});
db.person.insert({
name : 'Jyothi',
age : 23,
skills : ['html', 'ASP']
});
db.person.insert({
name : 'Varsha',
age : 30,
skills : ['.NET', 'Java']
});
db.person.insert({
name : 'Amogh',
age : 29,
skills : ['C#', 'ASP']
});
This JavaScript file contains some simple data, to be inserted into MongoDB server. It contains, persons name, age and skills(in array form) person is the collection name, we’re creating.
C:\mongodb>cd bin
C:\mongodb\bin>mongo 127.0.0.1/satish C:/temp/load.js
MongoDB shell version: 2.4.3
connecting to: 127.0.0.1/satish
C:\mongodb\bin>mongo
MongoDB shell version: 2.4.3
connecting to: test
C:\mongodb>cd bin
C:\mongodb\bin>mongo 127.0.0.1/satish C:/temp/load.js
MongoDB shell version: 2.4.3
connecting to: 127.0.0.1/satish
C:\mongodb\bin>mongo
MongoDB shell version: 2.4.3
connecting to: test
Once these data/documents are loaded into new database, we start operating on this data using comparison operator.
$lt – less than – Matches vales that are less than the value specified in the query. $lte – less than or equal to – Matches values that are less than or equal to the value specified in the query.