【C++】10.算术运算符

float 的精度是7位。double精度可以保证15位。

但是默认float和double都只能显示6位小数部分,

再多需要#include <iomanip>,

然后在输出语句之前插入cout << setprecision(20);强制输出小数位。

 

 

 double类型占8个字节——>sizeof(ff*dd)=  8

int类型占4字节

  •  cout <<(double)x / y ;是把 x 强制转换成double类型,再和 y 做除法运算。不是x和y先除,再把结果强制转换
  • int(‘A’)是把字符A 转成内码值

Arithmetic operators are fundamental operators in programming that allow you to perform various mathematical calculations on numerical values. These operators are used to carry out basic arithmetic operations like addition, subtraction, multiplication, division, and more. Here's an overview of the common arithmetic operators:

1. Addition (+): Adds two numerical values together.
  

   ```python
   result = 5 + 3  # result will be 8
   ```

2. Subtraction (-):Subtracts the right operand from the left operand.
  

   ```python
   result = 10 - 4  # result will be 6
   ```

3. Multiplication (*): Multiplies two numerical values together.
 

   ```python
   result = 7 * 2  # result will be 14
   ```

4. Division (/): Divides the left operand by the right operand. In many programming languages, if both operands are integers, division between them will result in an integer division (floor division), while using at least one floating-point operand will yield a floating-point result.
  

   ```python
   result = 15 / 4  # result will be approximately 3.75
   ```

5. Modulus (%):Returns the remainder when the left operand is divided by the right operand.
  

   ```python
   result = 20 % 3  # result will be 2 (20 divided by 3 leaves a remainder of 2)
   ```

6. Exponentiation ( or ^, depending on the programming language):Raises the left operand to the power of the right operand.
  

   ```python
   result = 2 ** 3  # result will be 8 (2 raised to the power of 3)
   ```

7. Floor Division (//):Performs integer division, resulting in the quotient without the remainder.
  

   ```python
   result = 15 // 4  # result will be 3 (integer division of 15 by 4)
   ```

These arithmetic operators are used extensively in programming to perform calculations and manipulate numerical values. They can be combined and used within expressions to create more complex mathematical operations. It's important to remember operator precedence (the order in which operators are evaluated) and to use parentheses when necessary to ensure the desired order of operations.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DFminer

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值