Cpp class exercise 1:修订间差异

跳转到导航 跳转到搜索
添加685字节 、​ 2019年3月21日 (星期四)
无编辑摘要
无编辑摘要
第26行: 第26行:


== 四则运算题 ==
== 四则运算题 ==
<syntaxhighlight lang="C++" line>
#include <iostream>
using namespace std;
int main()
{
    cout << 1 + 2 <<endl;
    cout << 3 - 1 <<endl;
    cout << 9 * 9 <<endl;
    cout << 9 / 9 <<endl;
    return 0;
}
</syntaxhighlight>


== 带输入输出的四则运算题 ==
== 带输入输出的四则运算题 ==


<syntaxhighlight lang="C++" line>
#include <iostream>
using namespace std;
int main()
{
    int i,j,k;
    cout << "请输入第1个数" <<endl;
    cin >> i;
    cout << "请输入第2个数" <<endl;
    cin >> j;
    k = i + j;
    cout << i << "+" << j << "=" << k <<endl;
    return 0;
}
</syntaxhighlight>
扩展,如果写成了i,会怎么样? 试着运行一下,看看输出结果是什么。想一想为什么?应该注意什么?


== 简单函数 ==
== 简单函数 ==
1,701

个编辑

导航菜单