C Language Basic Learning operator-Basic arithmetic operator

Source: Internet
Author: User
Tags integer division

Basic arithmetic operators

The operators in the C language for basic arithmetic operations are: +,-,*,%,/. The use of these operators is essentially the same as you might imagine:

The addition operator "+" causes the values on both sides of it to be added together.

The subtraction operator "-" subtracts the subsequent number from the number preceding it.

multiplication is represented by "*" . The C language does not have a function to calculate squares, and there is no exponential operator. But you can use multiplication to calculate the square.

the symbol "%" means redundancy. The result of the remainder operation is the remainder after dividing two numbers. Therefore, the value of the participating operation must be an integer.

the symbol "/" denotes division. Note that the division operation of a floating-point type gets a floating-point number result, and the integer division operation gets an integer result.

For example, 5/2 results are 2. When you mix integers and floating-point numbers, the result is a floating-point number, such as the 5/2.0 result is 2.5.

Let's see an example:

C code

  1. #include <stdio.h>

  2. int Main (void)

  3. {

  4. int a = 7;

  5. int b = 3;

  6. //Ask A to divide by the remainder of B and output the remainder

  7. //Write down your code here

  8. printf ("%d", a%b);

  9. return 0;

  10. }

The result of course is 1, more study content, in the code bud Net Http://www.mayacoder.com/lesson/index


C Language Basic Learning operator-Basic arithmetic operator

Related Article

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.