1.Assignment Operator (=):
using
System;
using
System.IO;
namespace
student
{
class
student
{
static
void
Main(string[]
args)
{
int
a;
int
b;
a
= 10;//Assignment
Operator
b
= 10;//Assignment
Operator
Console.WriteLine("a="
+ a.ToString());
Console.WriteLine("b="
+ b.ToString());
Console.ReadKey();
}
}
}
Output :a=10
b=10
Operator | What is ? | Expression | Result |
---|---|---|---|
+ | Do Number Addition | a=10,b=10 , c=a+b; | c is 20 |
- | Do Number Substraction | a=20,b=10 , c=a-b; | c is 10 |
* | Do Number Multiplicaion | a=20,b=10 , c=a*b; | c is 200 |
% | Return Reminder | a=21,b=10 , c=a%b; | c is 1 |
++ | Increment by One | a=10 , a++;; | a is 11 |
-- | Decrement by One | a=10 , a--; | a is 9 |
Example
using System;
using System;
using
System.IO;
namespace
student
{
class
student
{
static
void
Main(string[]
args)
{
int
a;
int
b;
int
c;
a
= 10;//Assignment
Operator
b
= 10;//Assignment
Operator
//+
Operator
c
= a + b;
Console.WriteLine("a+b="
+c.ToString() );
//-
Operator
c
= a - b;
Console.WriteLine("a-b="
+ c.ToString());
//*
Operator
c
= a * b;
Console.WriteLine("a*b="
+ c.ToString());
//
/ Operator
c
= a / b;
Console.WriteLine("a/b="
+ c.ToString());
//
% Operator
c
= a % b;
Console.WriteLine("a%b="
+ c.ToString());
//
++ Operator
a
++;
Console.WriteLine("a++="
+ a.ToString());
//
-- Operator
a
= 10;
a--;
Console.WriteLine("a--="
+ a.ToString());
Console.ReadKey();
}
}
}
Output :
a+b=20
a-b=0
a*b=100
a/b=1
a%b=0
a++=11
a--=9
Output :
a+b=20
a-b=0
a*b=100
a/b=1
a%b=0
a++=11
a--=9
Relational Operator
Output :
Operator | What is ? | Expression | Result |
---|---|---|---|
== | Check Equal | a=10,b=10 , a==b; | True |
> | Check Greater Than | a=11,b=10 , a>b; | True |
< | Check Less Than | a=10,b=11 ,a | True |
>= | Check Greater Than equal to | a=10,b=11 ,a>=b; | False |
<= | Check Greater Than equal to | a=10,b=11 ,a<=b; | True |
!= | Check Greater Than equal to | a=10,b=11 ,a!=b; | True |
using
System;
using
System.IO;
namespace
student
{
class
student
{
static
void
Main(string[]
args)
{
int
a;
int
b;
bool
c;
a
= 10;//Assignment
Operator
b
= 10;//Assignment
Operator
//==
Operator
c
= a == b;
Console.WriteLine("a==b:"
+c.ToString() );
//>
Operator
c
= a > b;
Console.WriteLine("a>b:"
+ c.ToString());
//<
Operator
c
= a < b;
Console.WriteLine("a
+ c.ToString());
//>=
Operator
c
= a >= b;
Console.WriteLine("a>=b:"
+ c.ToString());
//<=
Operator
c
= a <=b;
Console.WriteLine("a<=b:"
+ c.ToString());
//
!= Operator
Console.WriteLine("a!=:"
+ a.ToString());
Console.ReadKey();
}
}
}
Output :
a==b:True
a>b:False
aa>=b:True
a<=b:True
a!=:10
a>b:False
aa>=b:True
a<=b:True
a!=:10
No comments:
Post a Comment