0% found this document useful (0 votes)
14 views4 pages

427445

The document contains multiple C++ code snippets demonstrating various programming concepts including structures, bitwise operations, loops, and conditional statements. Each snippet is self-contained and performs different operations, with outputs printed to the console. The document showcases a range of programming techniques and logic implementations in C++.

Uploaded by

Xbit Smarty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

427445

The document contains multiple C++ code snippets demonstrating various programming concepts including structures, bitwise operations, loops, and conditional statements. Each snippet is self-contained and performs different operations, with outputs printed to the console. The document showcases a range of programming techniques and logic implementations in C++.

Uploaded by

Xbit Smarty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1 #include <iostream>

2 using namespace std;


3
4 struct str {
5 int t[3];
6 char s[3];
7 };
8
9 int main() {
10 str a = { 1, 2, 3, 'a', 'b', 'c' };
11 str b = { 5, 6, 7, 'x', 'y', 'z' };
12 cout << char(b.s[0] + a.t[0]) << int(a.s[2] - a.s[0]) << int(b.s[2] - b.s[1]);
13 return 0;
14 }
15
16
17
18
19 #include <iostream>
20 using namespace std;
21 int main() {
22 int a = 1, b = 2;
23 int c = a << b;
24 int d = 1 << c;
25 int e = d >> d;
26 cout << e;
27 return 0;
28 }
29
30
31
32
33 #include <iostream>
34 using namespace std;
35 int main() {
36 int a = 2;
37 switch(a << a) {
38 case 8 : a++;
39 case 4 : a++;
40 case 2 : break;
41 case 1 : a--;
42 }
43 cout << a;
44 return 0;
45 }
46
47
48
49
50
51 #include <iostream>
52 using namespace std;
53 int main() {
54 int i = 3, j = 0;
55 do {
56 i--;
57 j++;
58 } while(i >= 0);
59 cout << j;
60 return 0;
61 }
62
63
64
65
66
67 #include <iostream>
68 using namespace std;
69
70 struct str {
71 int t[3];
72 char s[3];
73 };
74
75 int main() {
76 str z[3];
77 for(int i = 0; i < 3; i++)
78 for(int j = 0; j < 3; j++) {
79 z[i].s[j] = '0' + i + j;
80 z[j].t[i] = i + j;
81 }
82 cout << z[0].s[1] << z[1].t[2] << z[2].s[0];
83 return 0;
84 }
85
86 #include <iostream>
87 using namespace std;
88
89 int main() {
90 char arr[5] = { 'a', 'b', 'c', 'd', 'e' };
91 for(int i = 1; i < 5; i++) {
92 cout << "*";
93 if((arr[i] - arr[i - 1]) % 2)
94 continue;
95 cout << "*";
96 }
97 return 0;
98 }
99
100 #include <iostream>
101 using namespace std;
102 int main() {
103 bool t[5];
104 for(int i = 0; i < 5; i++)
105 t[4 - i] = !(i % 2);
106 cout << t[0] && t[2];
107 return 0;
108 }
109
110 #include <iostream>
111 using namespace std;
112 int main() {
113 int a = 1, b = 2;
114 int c = a | b;
115 int d = c & a;
116 int e = d ^ 0;
117 cout << e << d << c;
118 return 0;
119 }
120
121 #include <iostream>
122 using namespace std;
123 int main() {
124 for(float val = -10.0; val < 100.0; val = -val * 2) {
125 if(val < 0 && -val >= 40)
126 break;
127 cout << "*";
128 }
129 return 0;
130 }
131
132 #include <iostream>
133 using namespace std;
134
135 struct sct {
136 int t[2];
137 };
138
139 struct str {
140 sct t[2];
141 };
142
143 int main() {
144 str t[2] = { {0, 2, 4, 6}, {1, 3, 5, 7} };
145 cout << t[1].t[0].t[1] << t[0].t[1].t[0];
146 return 0;
147 }
148
149
150 int i = 1, j = i++, k = --i;
151 if(i > 0) {
152 j++;
153 k++;
154 }
155 else {
156 k++;
157 i++;
158 }
159 if(k == 0) {
160 i++;
161 j++;
162 }
163 else {
164 if(k > 0)
165 k--;
166 else
167 k++;
168 i++;
169 }
170 cout << i * j * k;
171
172
173 double big = 1e15;
174 double small = 1e-15;
175
176 cout << fixed << big + small;
177
178
179 #include <iostream>
180 using namespace std;
181 int main() {
182 float val = 100.0;
183 do {
184 val = val / 5;
185 cout << "*";
186 } while(val > 1.0);
187 return 0;
188 }
189
190 int i = 0, j = i++, k = --i;
191 if(i > 0)
192 j++;
193 else
194 k++;
195 if(k == 0)
196 i++;
197 else if(k > 0)
198 k--;
199 else
200 k++;
201 cout << i * j * k;
202
203 #include <iostream>
204 using namespace std;
205 int main() {
206 int g[3][3] = {{2, 4, 8}, {3, 6, 9}, {5, 10, 15}};
207 for(int i = 2; i >= 0; i--)
208 for(int j = 0; j < 3; j++)
209 g[i][j] += g[j][i];
210 cout << g[1][1];
211 return 0;
212 }
213
214 #include <iostream>
215 using namespace std;
216 int main() {
217 for(float val = -10.0; val < 100.0; val = -val * 2)
218 cout << "*";
219 return 0;
220 }
221
222 #include <iostream>
223 using namespace std;
224 int main() {
225 int t[] = { 8, 4, 3, 2, 1 }, i;
226 for(i = t[4]; i < t[0]; i++)
227 t[i - 1] = -t[3];
228 cout << i;
229 return 0;
230 }
231
232 #include <iostream>
233 using namespace std;
234 int main() {
235 int i = 5, j = 0;
236 while(i > 0) {
237 i--;
238 j++;
239 }
240 cout << j;
241 return 0;
242 }
243
244 #include <iostream>
245 using namespace std;
246 int main() {
247 int a[] = {4, 0, 3, 1, 2};
248 int b[] = {1, 2, 3, 4, 5};
249
250 for(int i = 0; i < 5; i++)
251 b[a[i]] = b[4 - i];
252 cout << b[0] << b[4];
253 return 0;
254 }
255
256 bool yes = !false;
257 bool no = !yes;
258 if(!no)
259 cout << “true”;
260 else
261 cout << “false” ;
262
263

You might also like