C# Mathematical Operations

C# Mathematical Operations

Mathematics rules also apply in programming languages. Process priority;

  1. inside parentheses
  2. Multiplication and division operations
  3. Addition and subtraction operations

Mod Retrieval (Finding the remainder)

Finding the remainder of the number after a division operation is called modulation. The operator for modding is the % character. 

For example, to find the remainder of dividing 5 by 2, we can write 5 % 2. The result will be 1.

Sample:

int a, b, c;

a = b % c; // variable b is divided by c and the remainder is written to a

int x = 10 % 5; // result 0

int y = 200 % 60; // result 20

 

Mathematical Abbreviations

For example, if we want to increase the value of a numeric variable a by 1, we can use one of the following lines. 

a = a + 1;

a++ ;

a += 1 ;

Likewise, if we want to decrease the value of the variable by 1;

a = a - 1;

a -- ;

a -= 1 ;

The ++ and -- operators can be used for increment and decrement. Abbreviations such as the following can be used for multiplication and division operations.

a = a * 5 ;

a *= 5 ;

 

a = a / 5 ;

a /= 5;

 

c# mathematical operations examples, mathematical operations, mode taking examples, finding the remainder, c# equation examples

EXERCISES

There are no examples related to this subject.



COMMENTS




Read 814 times.

Online Users: 504



c-sharp-mathematical-operations