# Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

## "Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

The operator in C#:-

It is used to perform an operation using operand,  operand can be variable, constant, and literals. C# support all operators of C and C++.

c=a+b // here a and b is the variable type operand

10+20  // here 10 and 20 are the literals

Type of Operator:-

1) Unary Operator:-   It will work using a single operand

1.1.1)  Increment|Decrement  :-

++ (increment) ,--(decrement)

Post  :-     ++,--  a++,a--  (first perform other operation then increment or decrements)

Pre  :-      ++,--, ++a,--a  (First increment or decrement then perform other operation)

the best example of post and pre-increment and decrement in C# programming languages.

using System;

class Inc
{
public static void Main()
{
int a=2,b;
b=a++;   //assignment means
Console.WriteLine("a="+a+" b="+b);

}

}

2) Binary Operator:-
It will work using a minimum of Two Operand

2.1.1)   Arithmetic :-    +,-,*,/,%

2.1.2)  Conditional:-    <,>,<=,>=,!=

2.1.3)  Assignment:-    =,+=,-=,*=,/=

2.1.4)  Logical :-     &&, ||, !

2.1.5)  Comparison:-    ==, equals()

3) Ternary Operator:-   It is used to solve the condition-based problem using a single-line statement

var = (condition)  ?    true  :   false;

Q) Example of the ternary operator to calculate a greater number program using two different numbers?

Solution:-

int a=5,b=2;

String s = (a>b)?"a is greater": " b is greater";

Console.WriteLine(s);

Program to check that entered number is an even number or an odd number?

The solution of this program:-

class TernaryExample
{
public static void Main()
{
int num;
Console.WriteLine("Enter number");
String s = (num % 2 == 0) ? "Even Number" : "Odd Number";
Console.WriteLine(s);
}
}

Assignment:-

1)  WAP to check leap year using ternary operator?

2)  WAP to check that entered char is vowel or consonant?

3)  WAP to calculate the greatest number using three different numbers using the ternary operator?

4)  WAP to calculate the area of the triangle using heron's formula?

5)  WAP to check that number is Armstrong's number or not?

6)  Solve this expression

int a=2,b=5;

b = a++ + a++ + ++a + a++;

b = ++a + a-- + --a + a--;

1. Ans 3):-Calculate the greatest number.

Console.WriteLine("Enter any Num1 :");
Console.WriteLine("Enter any Num2 :");
Console.WriteLine("Enter any Num3 :");
int R = (a>b && a>c)? a :((b>a && b>c)? b:c);
Console.Write("Largest number is :{0}",R);

2. Ans 1):- Leap Year or not?

int y;
Console.Write("Enter the Year : ");
string s =(y%4 == 0 && y%100 != 0)?"It is a Leap Year":"It is not a Leap Year";
Console.WriteLine("The Year is :{0}",s);

3. Ans 2):-

{
char xy;
Console.WriteLine("Enter Alpha : ");
if (xy =='a'|| xy =='e'|| xy =='i'|| xy =='o'|| xy =='u'|| xy =='A'|| xy =='E'|| xy =='I'|| xy =='O'|| xy =='U')
{
Console.WriteLine("Vowel");
}
else
{
Console.WriteLine("Consonant");

1. using ternary
char xy;
Console.WriteLine("Enter Alpha : ");
String s= (xy == 'a' || xy == 'e' || xy == 'i' || xy == 'o' || xy == 'u' || xy == 'A' || xy == 'E' || xy == 'I' || xy == 'O' || xy == 'U')?" Vowel" : " Consonent";
Console.WriteLine(s);

4. Program to calculate area of triangle using herons formula in c#
class CalulateTriangle
{
public static void Main()
{
int a = 3000, b = 200, c = 100;
int s;
s = (a + b + c) / 2;
double tarea = Math.Sqrt(s * (s - a) * (s - b) * (s - c));
Console.WriteLine("Area is {0}", tarea);

}
}

5. Solution of Armstrong number in C#?

class ArmstrongNumber
{
static void Main()
{
int num = 183,num1;
num1 = num; //153
int a = num1 % 10; //3
num1 = (int)(num1 / 10); //15
int b = num1 % 10; //5
int c =(int)(num1 / 10); //1

int actualnumber = (a * a * a) + (b * b * b) + (c * c * c);
String s = num == actualnumber ? "armstrong" : "not armstrong";
Console.WriteLine(s);