C语言编程:输入整数a和b,如果a能被b整除,就输出算式和商,否则输出算式、整数商和余数。
时间: 2024-05-15 09:16:46 浏览: 8
```c
#include <stdio.h>
int main()
{
int a, b, quotient, remainder;
printf("请输入两个整数a和b:\n");
scanf("%d%d", &a, &b);
if (a % b == 0) {
quotient = a / b;
printf("%d/%d=%d\n", a, b, quotient);
} else {
quotient = a / b;
remainder = a % b;
printf("%d/%d=%d...%d\n", a, b, quotient, remainder);
}
return 0;
}
```
相关问题
c语言编程实现:键盘输入两个整数a和6,输出a 除以6的商和余数
可以使用C语言中的除法运算符"/"和取模运算符"%"来实现这个功能。以下是代码示例:
```c
#include <stdio.h>
int main() {
int a, b;
printf("请输入两个整数:\n");
scanf("%d%d", &a, &b);
int quotient = a / b;
int remainder = a % b;
printf("%d 除以 %d 的商为 %d,余数为 %d\n", a, b, quotient, remainder);
return 0;
}
```
当用户输入a=10,b=6时,程序输出:
```
请输入两个整数:
10 6
10 除以 6 的商为 1,余数为 4
```
用基础c语言编程实现:键盘输入两个整数a和6,输出a 除以6的商和余数
以下是实现该功能的基础 C 语言代码:
```
#include <stdio.h>
int main() {
int a, b, quotient, remainder;
printf("请输入两个整数:\n");
scanf("%d %d", &a, &b);
quotient = a / b;
remainder = a % b;
printf("%d 除以 %d 的商为 %d,余数为 %d\n", a, b, quotient, remainder);
return 0;
}
```
输入两个整数,程序会计算它们的商和余数,并输出结果。
相关推荐
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)