# 输出

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <bits/stdc++.h>

using namespace std;

int a = 320; // 整数
double b = 2005.1018; // 小数
char c = 'x'; // 字符
string s = "jxufe-acm"; // 字符串

int main() {
// 1. cout 输出
// cout << 输出内容;
// cout << 输出内容 << 输出内容 ..... ;

cout << a << ' ' << b << ' ' << c << ' ' << s << '\n';

// cout << fixed << setprecision(位数) << 输出内容 ....
cout << fixed << setprecision(4) << b << '\n';

// 2. printf 输出
printf("%d %f %c\n", a, b, c);
// print - 打印,f? format,printf - 格式化输出
// 320 2005.101800 x
// printf("%?%?...", 输出内容1, 输出内容2);
printf("%d --- %d\n", a, a);
/*
%d -> int
%f -> float / double
%c -> char
printf 输出 string 暂时不讲,有兴趣的同学自己去研究
*/

// printf 保留小数位数?
printf("%.4f", b);
// printf("%.小数位数f", b);

// printf 指定宽度输出
// 自动补全 0 输出等后续讲完循环后,我们再进行补充
}

# 输入

c++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <bits/stdc++.h>

using namespace std;

int a;
string s;

int main() {
// 1. cin 输入

// cin >> 输入内容 >> 输出内容
// 针对字符串的输入问题,留到后面的字符串章节的同学讲

// 2. scanf 输入
// scanf("%d", &输入内容);
// f -> 格式化的意思
// scanf("%d", &a);
// printf("-%d", a); // - 会被输出

// scanf("-%d", &a);
// cout << a;

// 给你日期,格式是 2005-10-3,要你输出 2025,10,3
// int y, m, d;
// scanf("%d-%d-%d", &y, &m, &d);
// printf("%d,%d,%d", y, m, d);

// 补充 - c 语言如何输入输出字符串?
// c++ 才有 string
char *str;
scanf("%s", str);
printf("%s", str);
// 置于为什么要加 &,什么时候要加,什么时候不加,留给后面讲指针和引用的同学
// 大家现在只用记住即可
}

# 条件语句

c++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <bits/stdc++.h>
using namespace std;
int main() {
// 判断语句
// 我输入一个数,如果其大于 10,判断其是否大于 10,是则输出 yes,否则输出 no
int a; cin >> a;

if (a >= 10) {
cout << "YES";
}
else {
cout << "NO";
}

/*
if (条件判断语句) {
// 执行的语句
}
else {
// 执行的语句
}
*/

// 世界上很少有事情是非黑即白的
// a <= 10 输出 a + 10
// a > 10 && a <= 20 输出 a + 3
// a > 20 && a <= 30 输出 a * 4
// 都不满足输出 a * 100

if (a <= 10) {
cout << a + 10;
}
else if (a > 10 && a <= 20) {
cout << a + 3;
}
else if (a > 20 && a <= 30) {
cout << a * 4;
}
else {
cout << a * 100;
}


// 判断a是不是大于等于10的偶数=
// 判断的嵌套

if (a >= 10) {
if (a % 10 == 0) {
cout << "是!";
}
else {
cout << "不是!";
}
}
else {
cout << "不满足 >= 10";
}
}

# 循环

c++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <bits/stdc++.h>
using namespace std;
int main() {
// 现在,我想要输出 1 ~ 100,形如:
// 1 2 3 4 5 6 7 8 9 10 .... 99 100

// cout << 1 << ' ' << 2 << ' ' << 3 ....

// 1. for 循环

// for (int i = 1; i <= 100; i++) {
// cout << i << ' ';
// }

/*
for (循环变量定义; 循环条件; 改变循环变量的语句) {
// 执行的内容
}

1. 定义 2. 判断条件 3. 执行内容 4. 改变循环变量
*/

// 2. while 循环

// int i = 1;

// while (i <= 100) {
// cout << i << ' ';
// i += 1;
// }

/*
while (循环条件) {
// 执行内容
}
*/

// for (; i <= 100; ) {
// cout << i << ' ';
// i += 1;
// }

// for 和 while 本质上都是循环,但是具体适用场景,请自己慢慢摸索

// if - else if - else 可以嵌套,循环能不能嵌套呢?
// 答案是肯定的
// 九九乘法表

// printf ("1 * 1 = 1 ......)
// .....

// 先循环 - 9行
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= i; j++) {
printf("%d*%d=%-2d ", j, i, j * i);
}
printf("\n");
}

// printf 指定宽度输出
// 自动补全 0 输出等后续讲完循环后,我们再进行补充

// printf("%.小数位数", 小数变量 / 小数)
// printf("%宽度", 输出内容);

// 作业
}