编写程序:输入a,b两个数,分别求它们的积,商,余数
时间: 2023-04-02 18:04:40 浏览: 123
您好,这是一个简单的数学问题,我可以回答。请看下面的程序:
#include <stdio.h>
int main() {
int a, b, product, quotient, remainder;
printf("请输入两个整数:\n");
scanf("%d %d", &a, &b);
product = a * b;
quotient = a / b;
remainder = a % b;
printf("它们的积是:%d\n", product);
printf("它们的商是:%d\n", quotient);
printf("它们的余数是:%d\n", remainder);
return ;
}
相关问题
用java编写程序,输入两个整数a,b,求它们的商和余数并输出
好的,这是一个简单的Java程序,可以输入两个整数a和b,然后计算它们的商和余数并输出:
```java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入两个整数a和b:");
int a = scanner.nextInt();
int b = scanner.nextInt();
int quotient = a / b;
int remainder = a % b;
System.out.println("商为:" + quotient);
System.out.println("余数为:" + remainder);
}
}
```
你可以将这段代码复制到你的Java IDE中运行,输入两个整数a和b,程序将会输出它们的商和余数。
Java编写程序,输入两个整数a,b,求它们的商和余数并输出。
好的,以下是Java代码:
```
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
int b = scanner.nextInt();
int quotient = a / b;
int remainder = a % b;
System.out.println("商:" + quotient + " 余数:" + remainder);
}
}
```
请注意,这段代码假设输入的两个整数都是正数。如果输入的整数可能为负数,则需要对代码进行修改。