C++ 实例 - 实现两个数相加

C++ 教程 · 2019-02-26 10:28:46

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

实例

#include <iostream> using namespace std; int main() { int firstNumber, secondNumber, sumOfTwoNumbers; cout << "输入两个整数: "; cin >> firstNumber >> secondNumber; // 相加 sumOfTwoNumbers = firstNumber + secondNumber; // 输出 cout << firstNumber << " + " << secondNumber << " = " << sumOfTwoNumbers; return 0; }

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

输入两个整数: 
4
5
4 + 5 = 9

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

查看所有标签

The Little Typer

The Little Typer

Daniel P. Friedman、David Thrane Christiansen、Duane Bibby、Robert Harper、Conor Mcbride / MIT Press / 2018-10-16 / GBP 30.00

An introduction to dependent types, demonstrating the most beautiful aspects, one step at a time. A program's type describes its behavior. Dependent types are a first-class part of a language, and are......一起来看看 《The Little Typer》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具