10-12c# Basics-Operator

Source: Internet
Author: User
Tags arithmetic operators

10-12c# Basics-Operator

Pre-class assignments: the name and age of the number in the class are written and aggregated.

I. Classification of Operators

1, mathematical operators (7)

1) + (plus)

Cases:

2)-(minus)

Cases:

3) * (multiplication sign)

Cases:

4)/(Division sign)

Cases:

5)% (number, whichever is the remainder)

Cases:

6) + + (increment character) automatic operation +1

? prefix increment operator:

Cases:

Postfix increment operator:

Cases:

Although the results are the same, the difference is that:

? ,//prefix increment operator: The first operation, then the assignment, and the last semicolon is the result of the assignment.

int y=++x;

equivalent to x=x+1;

int y=x;

Cases:

',///suffix increment operator: First assignment, after operation, and final semicolon after the result of assignment

int y=x + +;

Equivalent to int y=x;

x=x+1;

Cases:

7)--(decrement character) automatic operation minus 1

The calculation method is the same as the increment operator, where only the difference between the prefix decrement operator and the Postfix decrement operator is emphasized:

Exercise 1: Calculate the area of the Circle:

2, relational operators (6). Returns only true or FALSE.

1) = =

2)! = (not equal to)

3) <

4) >

5) <=

6) >=

2, logical operators (3).

1) and (&&) equal to and, several conditions must be met before execution

2) or (| | Equivalent or, only one or a few of these conditions can be satisfied.

3) Non-(! Equivalent to No, as long as the condition does not satisfy the return of true, applied in front of the parentheses of the expression.

4. Other operators

? assignment operators

1) = (equals)

2) + = (not equal to)

3)-=

4) *=

5)%=

6)/=

?:< Span style= "font-family: ' Song body '; font-size:16pt; Mso-spacerun: ' Yes '; >x;// x>12, so X=X-12; x=x.

Example: Hourly System

Exercise 2: Judging whether a student's score is passed (60 points)

Exercise 3: Judge whether the number within 0-100 is prime?

Exercise 4: Determine whether the integer within 0-200 is related to the whole ;

Precedence of operators (top-down)

1)!

2) Arithmetic operators

+ +,--

*,/,%

+,-

3) Relational operators

<,>,<=,>=

= =,!=

4) Logical operators

&&

||

Cases:

10-12c# Basics-Operator

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.