C++ 实例 - 求商及余数

C++ 教程 · 2019-02-26 10:43:02

使用 C++ 获取用户的输入两个数字,并将两个数字相除,然后将商和余数输出到屏幕:

实例

#include <iostream> using namespace std; int main() { int divisor, dividend, quotient, remainder; cout << "输入被除数: "; cin >> dividend; cout << "输入除数: "; cin >> divisor; quotient = dividend / divisor; remainder = dividend % divisor; cout << "商 = " << quotient << endl; cout << "余数 = " << remainder; return 0; }

以上程序执行输出结果为:

输入被除数: 13
输入除数: 4
商 = 3
余数 = 1

点击查看所有 C++ 教程 文章: https://codercto.com/courses/l/18.html

查看所有标签

The Black Box Society

The Black Box Society

Frank Pasquale / Harvard University Press / 2015-1-5 / USD 35.00

Every day, corporations are connecting the dots about our personal behavior—silently scrutinizing clues left behind by our work habits and Internet use. The data compiled and portraits created are inc......一起来看看 《The Black Box Society》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

随机密码生成器
随机密码生成器

多种字符组合密码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码