乘除法编程码怎么写

时间:2025-01-26 14:44:49 网络游戏

C语言

```c

int a = 10;

int b = 5;

int result = a + b; // 加法

int diff = a - b; // 减法

int product = a * b; // 乘法

float quotient = (float)a / b; // 除法

int remainder = a % b; // 取余数

```

Python

```python

a = 10

b = 5

result = a + b 加法

diff = a - b 减法

product = a * b 乘法

quotient = a / b 除法

remainder = a % b 取余数

```

Java

```java

int a = 10;

int b = 5;

int result = a + b; // 加法

int diff = a - b; // 减法

int product = a * b; // 乘法

float quotient = (float)a / b; // 除法

int remainder = a % b; // 取余数

```

JavaScript

```javascript

let a = 10;

let b = 5;

let result = a + b; // 加法

let diff = a - b; // 减法

let product = a * b; // 乘法

let quotient = a / b; // 除法

let remainder = a % b; // 取余数

```

C++

```cpp

include

int main() {

int a = 10;

int b = 5;

int result = a + b; // 加法

int diff = a - b; // 减法

int product = a * b; // 乘法

float quotient = static_cast(a) / b; // 除法

int remainder = a % b; // 取余数

std::cout << "Result: " << result << std::endl;

return 0;

}

```

Ruby

```ruby

a = 10

b = 5

result = a + b 加法

diff = a - b 减法

product = a * b 乘法

quotient = a / b.to_f 除法

remainder = a % b 取余数

```

PHP

```php

$a = 10;

$b = 5;

$result = $a + $b; // 加法

$diff = $a - $b; // 减法

$product = $a * $b; // 乘法

$quotient = $a / $b; // 除法

$remainder = $a % $b; // 取余数

```

这些示例展示了如何在不同编程语言中实现基本的加减乘除运算。根据你的具体需求和使用的编程语言,可以选择合适的代码片段进行参考。