-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample4.src
More file actions
104 lines (89 loc) · 1.6 KB
/
Copy pathsample4.src
File metadata and controls
104 lines (89 loc) · 1.6 KB
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
// ================================
// DIFFICULT TEST PROGRAM
// Tests: nested loops, nested if,
// float, arithmetic, conditions
// ================================
// Basic variables
int a = 10;
int b = 3;
int c = 7;
int d = 2;
// Complex arithmetic
int expr1 = a + b * c - d;
int expr2 = a * b + c * d;
int expr3 = a * a - b * b;
print(expr1);
print(expr2);
print(expr3);
// Nested if else
int x = 50;
int y = 30;
int z = 50;
if (x > y) {
if (x == z) {
int same = 1;
print(same);
} else {
int diff = 0;
print(diff);
}
} else {
int smaller = 99;
print(smaller);
}
// Float calculations
float base = 6;
float height = 4;
float area = base * height;
float half = area - area;
print(area);
// Loop with condition inside
int i = 1;
int limit = 10;
int total = 0;
while (i < limit) {
total = total + i;
i = i + 1;
}
print(total);
// Nested loop simulation using counter
int outer = 1;
int inner = 0;
int count = 3;
while (outer < count) {
inner = 1;
while (inner < count) {
int cell = outer * inner;
print(cell);
inner = inner + 1;
}
outer = outer + 1;
}
// Even number sum using loop
int num = 2;
int top = 11;
int esum = 0;
while (num < top) {
esum = esum + num;
num = num + 2;
}
print(esum);
// Power of 2 loop
int power = 1;
int steps = 8;
int step = 0;
while (step < steps) {
print(power);
power = power * 2;
step = step + 1;
}
// Final condition check
int final = 999;
int check = 1000;
if (final < check) {
int pass = 1;
print(pass);
} else {
int fail = 0;
print(fail);
}