3、输入两个非0整数,计算并输出两个数的和、差、积、商、余数和平均值。
时间: 2023-07-10 11:13:20 浏览: 123
好的,我来回答你的问题。以下是计算两个非零整数的和、差、积、商、余数和平均值的程序:
```python
a = int(input("请输入第一个非零整数:"))
b = int(input("请输入第二个非零整数:"))
sum = a + b # 计算两数之和
difference = a - b # 计算两数之差
product = a * b # 计算两数之积
quotient = a / b # 计算两数之商
remainder = a % b # 计算两数之余数
average = (a + b) / 2 # 计算两数之平均数
# 输出结果
print("两个数的和为:", sum)
print("两个数的差为:", difference)
print("两个数的积为:", product)
print("两个数的商为:", quotient)
print("两个数的余数为:", remainder)
print("两个数的平均数为:", average)
```
你可以直接复制以上代码到 Python 环境中进行运行,输入任意两个非零整数即可得到结果。希望能帮到你!
相关问题
编写一个JAVA程序,要求用户输入两个整数num1和num2,然后输出它们的和、差、积、商、余数、平均数和最大值。
```
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入两个整数:");
int num1 = scanner.nextInt();
int num2 = scanner.nextInt();
int sum = num1 + num2;
int diff = num1 - num2;
int product = num1 * num2;
int quotient = num1 / num2;
int remainder = num1 % num2;
double average = (double)(num1 + num2) / 2;
int max = num1 > num2 ? num1 : num2;
System.out.println("和:" + sum);
System.out.println("差:" + diff);
System.out.println("积:" + product);
System.out.println("商:" + quotient);
System.out.println("余数:" + remainder);
System.out.println("平均数:" + average);
System.out.println("最大值:" + max);
}
}
```
编写一个 JAVA 程序,要求用户输入两个整数num1和num2,然后输出它们的和、差、积、商、余数、平均数和最大值。
```java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入第一个整数:");
int num1 = scanner.nextInt();
System.out.print("请输入第二个整数:");
int num2 = scanner.nextInt();
// 计算和、差、积、商、余数、平均数和最大值
int sum = num1 + num2;
int diff = num1 - num2;
int product = num1 * num2;
int quotient = num1 / num2;
int remainder = num1 % num2;
double average = (num1 + num2) / 2.0;
int max = num1 > num2 ? num1 : num2;
// 输出结果
System.out.println("和:" + sum);
System.out.println("差:" + diff);
System.out.println("积:" + product);
System.out.println("商:" + quotient);
System.out.println("余数:" + remainder);
System.out.println("平均数:" + average);
System.out.println("最大值:" + max);
}
}
```
阅读全文