Arithmetic operators in c#
Used to
perform common mathmetical calculations.
There are
five arithmetica;l operators.
+,-,*,/,%
operator
|
Purpose.
|
+
|
Addition
|
-
|
Subtraction
|
*
|
Multiplication.
|
/
|
Division.
|
%
|
Reminder while
dividing(Modulus operator).
|
Consider a
and b as integer variables whose values are 10 and 3 respectively.
Expression
|
Values
|
a+b
|
13
|
a-b
|
7
|
a*b
|
30
|
a/b
|
3
|
a%b
|
1
|
Consider x
and y be floating point variables and their vsalues are 12.5 and 2.0
respectively
Expression
|
Values
|
X+y
|
14.5
|
x-y
|
10.5
|
X*y
|
25
|
x/y
|
6.25.
|
Sample program
performing multiplication operator.
using System;
class Program
{
static void Main(string[] args)
{
double rad, area;
Console.WriteLine("Enter radius of circle: ");
rad = double.Parse(Console.ReadLine());
area = Math.PI * rad * rad;
Console.WriteLine("area of circle={0}", area);
Console.ReadLine();
}
}
output:
--Muthu karthikeyan,Madurai.
No comments:
Post a Comment