-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource.cx
149 lines (131 loc) · 4.04 KB
/
source.cx
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
int main() {
//---------------------------
// Test function declaration
//---------------------------
int fun_one(int a, int b);
int fun_two(int, int x, int y);
int fun_three();
//---------------------------
// Test variable declaration
//---------------------------
int a = 5 * 2 - 3; // Multiplication and subtraction
int b = (a % 3) + 4; // Modulus and addition
int sum = a + b * 2; // Combination of addition and multiplication
int i = (b > 5) ? a : b; // Ternary expression
int k = (sum / 2) + 1; // Division and addition
int result = (k > i) ? (k - i) : (i - k); // Another ternary expression
//----------------------------------
// TODO: Bitwise operation examples
//----------------------------------
// int j = (sum & 1) ? sum - 1 : sum + 1; // Bitwise AND with conditional
// int m = (k << 2) - j; // Left shift and subtraction
// int x = m ^ k; // Bitwise XOR
// int y = ~x & 0xF; // Bitwise NOT and AND mask
//--------------------------
// TODO: Test function calls
//--------------------------
// result = fun_one(a, b);
// sum = fun_two(result, x, y);
//-------------------------
// If-else structure
//-------------------------
if (a <= 10) {
sum = a;
} else if (a == b) {
sum = a + b;
} else {
sum = b;
}
//-----------------------------
// For loop: all parts present
//-----------------------------
for (int k = 0; k < 3; k = k + 1) {
sum = sum + k;
}
//------------------------------------
// For loop with empty initialization
//------------------------------------
for (; a < 8; a = a + 1) {
sum = sum + a;
}
//-------------------------------
// For loop with empty condition
//-------------------------------
for (int y = 0;; y = y + 1) {
sum = sum + y;
if (y >= 2) {
break;
}
}
//-------------------------------
// For loop with empty increment
//-------------------------------
for (int m = 0; m < 3;) {
sum = sum + m;
m = m + 1;
}
//-------------------------
// TODO: While loop test
//-------------------------
// while (i < 5) {
// sum = sum + i;
// i = i + 1;
// }
//--------------------------
// TODO: Do-while loop test
//--------------------------
// do {
// sum = sum - 1;
// } while (sum > 10);
//--------------------------
// More ternary expressions
//--------------------------
a = (a > b) ? a : b;
b = (a == b) ? a + b : a - b;
sum = (sum > 20) ? sum - 5 : sum + 5;
//----------------------------------
// Additional nested if-else blocks
//----------------------------------
if (a > 0) {
if (b > 0) {
sum = sum + a + b;
} else {
sum = sum - a;
}
} else {
sum = sum + 1;
}
//-------------------------
// TODO: Switch-case test
//-------------------------
// switch (sum) {
// case 5:
// sum = sum + 10;
// break;
// case 10:
// sum = sum - 3;
// break;
// default:
// sum = sum * 2;
// }
//-------------------------
// Null statement
//-------------------------
;
//-------------------------
// Nested ternary for complexity
//-------------------------
i = (j > 0) ? ((j > 10) ? j - 1 : j + 2) : (j - 2);
//-------------------------
// TODO: Function call inside an expression
//-------------------------
// result = fun_three() + fun_one(a, b);
//-------------------------
// Final computation
//-------------------------
sum = sum + i + j + x + result;
//-------------------------
// Return the final result
//-------------------------
return sum;
}