If If Else Else If Else
If If Else Else If Else
2 {
3 int i = 2;
4 float a = 3;
5 bool f1 = i > a, f2 = a > i, f3 = a / i > i / a;
6 if (f3)
7 if (f2)
8 i += 1;
9 else
10 i += 2;
11 else if (f1)
12 i += 3;
13 else
14 i += 4;
15 cout << i << endl;
16 }
17 //
18 //
19 int main(void)
20 {
21 int i = 10;
22 float a = 1000.0;
23 while (i > 0)
24 {
25 i /= 2;
26 a /= 10;
27 }
28 cout << a << endl;
29 }
30 //
31 //
32 int main(void)
33 {
34 int i = 10;
35 float a = -1.0;
36 while (i < 0)
37 {
38 a = a + 10.0 * a / -10;
39 --i;
40 }
41 cout << i << endl;
42 }
43 //
44 //
45 int main(void)
46 {
47 float a;
48 int i = 0;
49 for (a = .009; a < 1e2; a *= 1e1)
50 i++;
51 cout << i << endl;
52 }
53 //
54 int main(void)
55 {
56 int i = 1, j = 2;
57 if (i > j && j > i)
58 i++;
59 if (i > j || j > i)
60 j++;
61 if (i | j)
62 i++;
63 if (i & j)
64 j++;
65 cout << i * j << endl;
66 }
67 int main(void)
68 {
69 int i = 1, j = 2, k;
70 i = i << j;
71 j = j << i;
72 k = j >> i;
73 cout << k << endl;
74 }
75 //
76 //
77 int main(void)
78 {
79 int t[5];
80 for (int i = 0; i < 5; i++)
81 t[i] = 2 * i * i;
82 cout << t[4] / t[1] << endl;
83 }
84 //
85 //
86 int main(void)
87 {
88 float arr[3][3] = { {.1, 1., 10.}, {10., .1, 1.}, {.1, 10., 1.} };
89 float x = 1.;
90 for (int i = 0; i < 3; i++)
91 x *= arr[i][i];
92 cout << x << endl;
93 }
94 //
95 //
96 struct A
97 {
98 int a;
99 float b;
100 };
101 struct B
102 {
103 int b;
104 float a;
105 };
106 struct C
107 {
108 A a;
109 B b;
110 };
111 int main (void)
112 {
113 C c1 = { 1, 2, 3, 4 }, c2 = { 5, 6, 7, 8 };
114 cout << c1.b.a + c2.a.b << endl;
115 }
116 //
117 struct A
118 {
119 int a;
120 char b;
121 };
122 struct B
123 {
124 char a;
125 int b;
126 };
127 int main (void)
128 {
129 A a = { 2, 'A' };
130 B b = { 'C', 1 };
131 cout << b.a - a.b - b.b + a.a << endl;
132 }