arithmetic operators

C language self-learning arithmetic operators

 1 #include <stdio.h>
 2 
 3 int main()
 4 {
 5     int x=10,y=-3;//2中表达方式;
 6     //x = 10;
 7     //y = -3;
 8     printf("x+y=%d\n",x+y   );
 9     printf("x-y=%d\n", x-y  );
10     printf("x*y=%d\n",x*y  );
11     printf("x/y=%d\n", x/ y );
 12      printf( " x%%y=%d\n " ,x%y ); // Why %% is the correct expression needs to be verified 
13      return  0 ;
 14  }
Pay attention to the division operation:
 
        If the two numbers to be divided are both integers, the result is also an integer, and the decimal part is omitted, such as 8/3 = 2; if one of the two numbers is a decimal, the result is a decimal, such as: 9.0/2 = 4.500000 .

Pay attention to the remainder operation:
 
        This operation is only suitable for the remainder operation with two integers, such as: 10%3 = 1; and 10.0%3 is wrong; the sign after the operation depends on the sign of the modulo, such as (-10)%3 = -1; while 10%(-3) = 1.
 
Note: There is no exponentiation operator in C language, and arithmetic symbols such as × and ÷ cannot be used.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325027871&siteId=291194637