C++ 中的数学
#include <iostream> using namespace std; int main() { ////赋值运算符 int a; a = 100; //加减乘除模 int a, b = 5; int c = a + b; //a+b int c = a - b; //a-b int c = a * b; //a*b int c = a / b; //a/b int c = a % b; //a%b取整 //判断 if (true) //(逻辑) { cout << "a" << endl; } //循环 for (size_t i = 0; i < 10; i++) { cout << i << endl; } while (true) { cout << "看我卡死" << endl; } int a; do { cout << "请输入" << endl; cin >> a; } while (true); //分支 switch (/*变量*/a) { default: //如果全部没有,则执行这个 break; //终止 =>没了 } //逻辑判断 a == a; //a的内容全等于a a > a; //a大于 a < a; //a小于 a <= a; //a小于等于 a >= a; //a 大于等于 a || a; // a or a a&& a; //a and a a != a; //a 不等于a a += a; //加等于 a =+ a; a -= a; a =- a; return 0; }
以上代码,自己写!!!复制粘贴运行不了的哦
创建自己的第一个简单函数
#include <iostream> using namespace std; int hello_world() { string a; do { cout << "$:"; cin >> a; if (a == "hi" || a =="hello") { cout << "你好" << endl; } } while (true); } int main() { hello_world(); }
结果是:当你输入hi hello 时 ,输出你好,反之就没了

浙公网安备 33010602011771号