mirror of
https://github.com/kmc7468/cs420.git
synced 2025-12-15 23:18:48 +00:00
Reorganize tests
This commit is contained in:
3
examples/c/alignof.c
Normal file
3
examples/c/alignof.c
Normal file
@@ -0,0 +1,3 @@
|
||||
int main() {
|
||||
return _Alignof(const int) == 4;
|
||||
}
|
||||
19
examples/c/array.c
Normal file
19
examples/c/array.c
Normal file
@@ -0,0 +1,19 @@
|
||||
int sum(int len, int *p) {
|
||||
int result = 0;
|
||||
for (int i = 0; i < len; i++) {
|
||||
result += p[i];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int a[5];
|
||||
int len = 5;
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
a[i] = i;
|
||||
}
|
||||
|
||||
return sum(len, a) == 10;
|
||||
}
|
||||
16
examples/c/array2.c
Normal file
16
examples/c/array2.c
Normal file
@@ -0,0 +1,16 @@
|
||||
void init(int row, int col, int a[4][5]) {
|
||||
for (int i = 0; i < row; i++) {
|
||||
for (int j = 0; j < col; j++) {
|
||||
a[i][j] = i * j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int a[4][5];
|
||||
int row = 4, col = 5;
|
||||
|
||||
init(row, col, a);
|
||||
|
||||
return a[2][3] == 6;
|
||||
}
|
||||
13
examples/c/array3.c
Normal file
13
examples/c/array3.c
Normal file
@@ -0,0 +1,13 @@
|
||||
int* foo(int a[10]){
|
||||
return a;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int a[10];
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
(foo(a))[i] = i;
|
||||
}
|
||||
|
||||
return a[5] == 5;
|
||||
}
|
||||
10
examples/c/array4.c
Normal file
10
examples/c/array4.c
Normal file
@@ -0,0 +1,10 @@
|
||||
int main() {
|
||||
int a[10];
|
||||
int *p = a;
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
*(p++) = i;
|
||||
}
|
||||
|
||||
return a[5] == 5;
|
||||
}
|
||||
14
examples/c/array5.c
Normal file
14
examples/c/array5.c
Normal file
@@ -0,0 +1,14 @@
|
||||
int g_a[5] = {1, 2, 3};
|
||||
|
||||
int main() {
|
||||
int init = 1;
|
||||
int a[5] = {init, 2, 3, 4, -5, 6};
|
||||
int sum = 0;
|
||||
|
||||
for(int i = 0; i < 5; i++) {
|
||||
sum += a[i];
|
||||
sum += g_a[i];
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
10
examples/c/bar.c
Normal file
10
examples/c/bar.c
Normal file
@@ -0,0 +1,10 @@
|
||||
int bar(int x, int y, int z){
|
||||
int arith_mean = (x + y + z) / 3;
|
||||
int ugly_mean = (((x + y) / 2) * 2 + z) / 3;
|
||||
if (x == y) { return y; }
|
||||
else { return z; }
|
||||
}
|
||||
|
||||
int main() {
|
||||
return 1;
|
||||
}
|
||||
13
examples/c/bitwise.c
Normal file
13
examples/c/bitwise.c
Normal file
@@ -0,0 +1,13 @@
|
||||
int main() {
|
||||
unsigned char a = -1;
|
||||
unsigned char b = -128;
|
||||
unsigned char c = 127;
|
||||
unsigned char d = b | a; // -1 (255)
|
||||
unsigned char e = b & a; // -128 (128)
|
||||
unsigned char f = b & c; // 0 (0)
|
||||
unsigned char g = b | c; // -1 (255)
|
||||
unsigned char h = -1 ^ -1; // 0 (0)
|
||||
unsigned char i = -1 ^ 0; // -1 (255)
|
||||
|
||||
return d == 255 && e == 128 && f == 0 && g == 255 && h == 0 && i == 255;
|
||||
}
|
||||
18
examples/c/cmp.c
Normal file
18
examples/c/cmp.c
Normal file
@@ -0,0 +1,18 @@
|
||||
int int_greater_than(int i, unsigned int j) {
|
||||
if (i > j) return 1;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
int char_greater_than(char i, unsigned char j) {
|
||||
if (i > j) return 1;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
// cmp ugt
|
||||
int r1 = int_greater_than(-1, 1);
|
||||
// cmp sgt
|
||||
int r2 = char_greater_than(-1, 1);
|
||||
|
||||
return r1 == 1 && r2 == 0;
|
||||
}
|
||||
6
examples/c/comma.c
Normal file
6
examples/c/comma.c
Normal file
@@ -0,0 +1,6 @@
|
||||
int main()
|
||||
{
|
||||
int y = 2;
|
||||
int x = (y += 2, 2, y + 3);
|
||||
return x == 7;
|
||||
}
|
||||
3205
examples/c/complete_cond.c
Normal file
3205
examples/c/complete_cond.c
Normal file
File diff suppressed because it is too large
Load Diff
53
examples/c/complete_cond_gen.py
Normal file
53
examples/c/complete_cond_gen.py
Normal file
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""Make c program which uses complicated conditional expression
|
||||
|
||||
To make c program, execute `python3 make_cond.py > file_name.c`
|
||||
"""
|
||||
|
||||
import random
|
||||
|
||||
def eval_cond(arr_cond):
|
||||
"""Evaluate conditional expression
|
||||
"""
|
||||
if len(arr_cond) == 1:
|
||||
return arr_cond[0]
|
||||
new_arr_cond = []
|
||||
for cond_start in range(len(arr_cond) // 3):
|
||||
cond_val = arr_cond[3*cond_start + 1] if arr_cond[3*cond_start] else arr_cond[3*cond_start + 2]
|
||||
new_arr_cond.append(cond_val)
|
||||
return eval_cond(new_arr_cond)
|
||||
|
||||
def make_func(i):
|
||||
"""Make a function that contains a conditional expression
|
||||
"""
|
||||
func_signature = "int " + "func_" + str(i) + "()"
|
||||
variables = "abcdefghijklmnopqrstuvwxyzA"
|
||||
func_inner = []
|
||||
val_bitmap = []
|
||||
|
||||
# Variable initializiation
|
||||
for var in variables:
|
||||
val = random.randint(0, 1)
|
||||
val_bitmap.append(val)
|
||||
decl = "\tint " + var + " = " + str(val) + ";"
|
||||
func_inner.append(decl)
|
||||
|
||||
expr_val = eval_cond(val_bitmap)
|
||||
func_inner.append("\treturn (((a ? b : c) ? (d ? e : f) : (g ? h : i)) ? ((j ? k : l) ? (m ? n : o) : (p ? q : r)) : ((s ? t : u) ? (v ? w : x) : (y ? z : A))) == " + str(expr_val) + ";")
|
||||
|
||||
return "\n".join([func_signature, "{"] + func_inner + ["}"])
|
||||
|
||||
if __name__ == "__main__":
|
||||
src = ""
|
||||
return_stmt = "\treturn ("
|
||||
NUM_FUNC = 100
|
||||
for i in range(NUM_FUNC):
|
||||
src += make_func(i)
|
||||
src += "\n\n"
|
||||
return_stmt += "func_" + str(i) + "()"
|
||||
return_stmt += " && " if i != (NUM_FUNC - 1) else ") == "
|
||||
return_stmt += "1;"
|
||||
src += "int main()\n{\n" + return_stmt + "\n}\n"
|
||||
|
||||
print(src)
|
||||
6
examples/c/cond.c
Normal file
6
examples/c/cond.c
Normal file
@@ -0,0 +1,6 @@
|
||||
int main()
|
||||
{
|
||||
int y = 1;
|
||||
int x = 0;
|
||||
return ((x == y) ? 2 : 5) == 5;
|
||||
}
|
||||
13
examples/c/cond_and_loop.c
Normal file
13
examples/c/cond_and_loop.c
Normal file
@@ -0,0 +1,13 @@
|
||||
int main() {
|
||||
int i;
|
||||
int p = 2;
|
||||
int q = 5;
|
||||
int r = (0 ? ((p > q) ? (p -= 2) : (p += 2)) : (p + q));
|
||||
|
||||
for (i = 0; i < 11; ((i % 2) ? (i += 2) : ++i)) {
|
||||
if (i % 2) { p += q; }
|
||||
else { p += r; }
|
||||
}
|
||||
|
||||
return p == 34;
|
||||
}
|
||||
11
examples/c/fib2.c
Normal file
11
examples/c/fib2.c
Normal file
@@ -0,0 +1,11 @@
|
||||
int (fibonacci)(int n) {
|
||||
if (n < 2) {
|
||||
return n;
|
||||
}
|
||||
|
||||
return fibonacci(n - 2) + fibonacci(n - 1);
|
||||
}
|
||||
|
||||
int main() {
|
||||
return fibonacci(9) == 34;
|
||||
}
|
||||
20
examples/c/fib3.c
Normal file
20
examples/c/fib3.c
Normal file
@@ -0,0 +1,20 @@
|
||||
int fibonacci(int n) {
|
||||
int i = 0;
|
||||
int t1 = 0, t2 = 1, next_term = 0;
|
||||
|
||||
if (n < 2) {
|
||||
return n;
|
||||
}
|
||||
|
||||
for (i = 1; i < n; ++i) {
|
||||
next_term = t1 + t2;
|
||||
t1 = t2;
|
||||
t2 = next_term;
|
||||
}
|
||||
|
||||
return t2;
|
||||
}
|
||||
|
||||
int main() {
|
||||
return fibonacci(9) == 34;
|
||||
}
|
||||
22
examples/c/fib4.c
Normal file
22
examples/c/fib4.c
Normal file
@@ -0,0 +1,22 @@
|
||||
int fibonacci(int n) {
|
||||
int i = 0;
|
||||
int t1 = 0, t2 = 1, next_term = 0;
|
||||
|
||||
if (n < 2) {
|
||||
return n;
|
||||
}
|
||||
|
||||
i = 1;
|
||||
while (i < n) {
|
||||
next_term = t1 + t2;
|
||||
t1 = t2;
|
||||
t2 = next_term;
|
||||
++i;
|
||||
}
|
||||
|
||||
return t2;
|
||||
}
|
||||
|
||||
int main() {
|
||||
return fibonacci(9) == 34;
|
||||
}
|
||||
22
examples/c/fib5.c
Normal file
22
examples/c/fib5.c
Normal file
@@ -0,0 +1,22 @@
|
||||
int fibonacci(int n) {
|
||||
int i = 0;
|
||||
int t1 = 0, t2 = 1, next_term = 0;
|
||||
|
||||
if (n < 2) {
|
||||
return n;
|
||||
}
|
||||
|
||||
i = 1;
|
||||
do {
|
||||
next_term = t1 + t2;
|
||||
t1 = t2;
|
||||
t2 = next_term;
|
||||
++i;
|
||||
} while (i < n);
|
||||
|
||||
return t2;
|
||||
}
|
||||
|
||||
int main() {
|
||||
return fibonacci(9) == 34;
|
||||
}
|
||||
11
examples/c/fibonacci.c
Normal file
11
examples/c/fibonacci.c
Normal file
@@ -0,0 +1,11 @@
|
||||
int fibonacci(int n) {
|
||||
if (n < 2) {
|
||||
return n;
|
||||
}
|
||||
|
||||
return fibonacci(n - 2) + fibonacci(n - 1);
|
||||
}
|
||||
|
||||
int main() {
|
||||
return fibonacci(9) == 34;
|
||||
}
|
||||
8
examples/c/foo.c
Normal file
8
examples/c/foo.c
Normal file
@@ -0,0 +1,8 @@
|
||||
int foo(int x, int y, int z){
|
||||
if (x == y) { return y; }
|
||||
else { return z; }
|
||||
}
|
||||
|
||||
int main() {
|
||||
return foo(0, 1, -1) == -1;
|
||||
}
|
||||
9
examples/c/foo2.c
Normal file
9
examples/c/foo2.c
Normal file
@@ -0,0 +1,9 @@
|
||||
int main() {
|
||||
int i = 0;
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
int i = 0;
|
||||
int k = 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
13
examples/c/foo3.c
Normal file
13
examples/c/foo3.c
Normal file
@@ -0,0 +1,13 @@
|
||||
int g = 10;
|
||||
|
||||
int foo(int, int k);
|
||||
|
||||
int main() {
|
||||
int i = g;
|
||||
|
||||
return foo(i, i) == 30;
|
||||
}
|
||||
|
||||
int foo(int i, int j) {
|
||||
return i + j + g;
|
||||
}
|
||||
15
examples/c/foo4.c
Normal file
15
examples/c/foo4.c
Normal file
@@ -0,0 +1,15 @@
|
||||
int foo(int i, int j, int k) {
|
||||
return i + j + k;
|
||||
}
|
||||
|
||||
int (* foo2())(int, int, int){
|
||||
return foo;
|
||||
}
|
||||
|
||||
int (* (* foo3())())(int, int, int){
|
||||
return foo2;
|
||||
}
|
||||
|
||||
int main() {
|
||||
return foo3()()(2, 2, 2) == 6;
|
||||
}
|
||||
19
examples/c/for_continue_break.c
Normal file
19
examples/c/for_continue_break.c
Normal file
@@ -0,0 +1,19 @@
|
||||
int foo() {
|
||||
int sum = 0;
|
||||
|
||||
for(int i = 0; ;) {
|
||||
if(i == 5) break;
|
||||
if(i == 3) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
sum += i;
|
||||
i++;
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
int main() {
|
||||
return foo() == 7;
|
||||
}
|
||||
15
examples/c/gcd.c
Normal file
15
examples/c/gcd.c
Normal file
@@ -0,0 +1,15 @@
|
||||
int gcd(int a, int b) {
|
||||
a = (a > 0) ? a : -a;
|
||||
b = (b > 0) ? b : -b;
|
||||
|
||||
while(a != b) {
|
||||
if(a > b) { a -= b; }
|
||||
else { b -= a; }
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
int main() {
|
||||
return gcd(18, 21) == 3;
|
||||
}
|
||||
5
examples/c/integer_literal.c
Normal file
5
examples/c/integer_literal.c
Normal file
@@ -0,0 +1,5 @@
|
||||
int main() {
|
||||
short temp = 0;
|
||||
unsigned int temp2 = 4294967163;
|
||||
return (char)(temp ^ temp2) == 123;
|
||||
}
|
||||
5
examples/c/integer_literal2.c
Normal file
5
examples/c/integer_literal2.c
Normal file
@@ -0,0 +1,5 @@
|
||||
int main() {
|
||||
int temp = 0;
|
||||
// `0xFFFFFFFF` is translated as `unsigned int` not `int`
|
||||
return temp < 0xFFFFFFFF;
|
||||
}
|
||||
16
examples/c/logical_op.c
Normal file
16
examples/c/logical_op.c
Normal file
@@ -0,0 +1,16 @@
|
||||
int main() {
|
||||
int a = 0;
|
||||
int b = 0;
|
||||
int c = 0;
|
||||
int d = 0;
|
||||
|
||||
if ((a = 1) || (b = 1)) {
|
||||
b++;
|
||||
}
|
||||
|
||||
if ((c = 1) && (d = 1)) {
|
||||
d++;
|
||||
}
|
||||
|
||||
return b == 1 && d == 2;
|
||||
}
|
||||
8
examples/c/minus_constant.c
Normal file
8
examples/c/minus_constant.c
Normal file
@@ -0,0 +1,8 @@
|
||||
int a = -1;
|
||||
long b = -1l;
|
||||
float c = -1.5f;
|
||||
double d = -1.5;
|
||||
|
||||
int main() {
|
||||
return (a + b + (int)c + (long)d) == -4;
|
||||
}
|
||||
8
examples/c/negate.c
Normal file
8
examples/c/negate.c
Normal file
@@ -0,0 +1,8 @@
|
||||
int foo(int x, int y, int z){
|
||||
if (!(x == y)) { return y; }
|
||||
else { return z; }
|
||||
}
|
||||
|
||||
int main() {
|
||||
return foo(0, 1, -1) == 1;
|
||||
}
|
||||
15
examples/c/pointer.c
Normal file
15
examples/c/pointer.c
Normal file
@@ -0,0 +1,15 @@
|
||||
int* foo(int *a){
|
||||
return a;
|
||||
}
|
||||
|
||||
int main(){
|
||||
int a = 1;
|
||||
int *p = &a;
|
||||
int **p2 = &*&p;
|
||||
int *p3 = *&p;
|
||||
|
||||
*&*foo(*p2) += 1;
|
||||
*foo(p3) += 1;
|
||||
|
||||
return a == 3;
|
||||
}
|
||||
7
examples/c/return_void.c
Normal file
7
examples/c/return_void.c
Normal file
@@ -0,0 +1,7 @@
|
||||
void foo() {
|
||||
}
|
||||
|
||||
int main() {
|
||||
foo();
|
||||
return 1;
|
||||
}
|
||||
7
examples/c/shift.c
Normal file
7
examples/c/shift.c
Normal file
@@ -0,0 +1,7 @@
|
||||
int main() {
|
||||
char a = -1;
|
||||
char b = a << 1;
|
||||
unsigned char c = (unsigned char)b >> 1;
|
||||
|
||||
return b == -2 && c == 0x7F;
|
||||
}
|
||||
5
examples/c/simple.c
Normal file
5
examples/c/simple.c
Normal file
@@ -0,0 +1,5 @@
|
||||
int main()
|
||||
{
|
||||
int x = 1;
|
||||
return 1;
|
||||
}
|
||||
10
examples/c/simple_cond.c
Normal file
10
examples/c/simple_cond.c
Normal file
@@ -0,0 +1,10 @@
|
||||
int f(int x) {
|
||||
return x + 8;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int x = 0;
|
||||
int y = (x++ == 1) ? 1 : 2;
|
||||
|
||||
return f((x < y) ? x : 2) == 9;
|
||||
}
|
||||
9
examples/c/simple_for.c
Normal file
9
examples/c/simple_for.c
Normal file
@@ -0,0 +1,9 @@
|
||||
int main()
|
||||
{
|
||||
int i;
|
||||
int sum = 0;
|
||||
for (i = 0; i < 11; ++i) {
|
||||
sum += i;
|
||||
}
|
||||
return sum == 55;
|
||||
}
|
||||
11
examples/c/simple_if.c
Normal file
11
examples/c/simple_if.c
Normal file
@@ -0,0 +1,11 @@
|
||||
int (fibonacci)(int n) {
|
||||
if (n < 2) {
|
||||
n += 2;
|
||||
}
|
||||
|
||||
return fibonacci(n - 2) + fibonacci(n - 1);
|
||||
}
|
||||
|
||||
int main() {
|
||||
return 1;
|
||||
}
|
||||
3
examples/c/sizeof.c
Normal file
3
examples/c/sizeof.c
Normal file
@@ -0,0 +1,3 @@
|
||||
int main() {
|
||||
return sizeof(const int) == 4;
|
||||
}
|
||||
26
examples/c/struct.c
Normal file
26
examples/c/struct.c
Normal file
@@ -0,0 +1,26 @@
|
||||
typedef struct {
|
||||
char a;
|
||||
struct {
|
||||
int b[4][5];
|
||||
};
|
||||
double c;
|
||||
} Temp;
|
||||
|
||||
void init(int row, int col, int arr[4][5]) {
|
||||
for (int i = 0; i < row; i++) {
|
||||
for (int j = 0; j < col; j++) {
|
||||
arr[i][j] = i * j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
Temp temp;
|
||||
int row = 4, col = 5;
|
||||
init(row, col, temp.b);
|
||||
|
||||
Temp temp2;
|
||||
temp2 = temp;
|
||||
|
||||
return temp2.b[2][3] == 6;
|
||||
}
|
||||
18
examples/c/struct2.c
Normal file
18
examples/c/struct2.c
Normal file
@@ -0,0 +1,18 @@
|
||||
typedef struct {
|
||||
char a;
|
||||
struct {
|
||||
int b[4];
|
||||
};
|
||||
long c;
|
||||
} Temp;
|
||||
|
||||
int main() {
|
||||
const Temp temp = {1, {{2, 3, 4, 5}}, 6};
|
||||
|
||||
Temp temp2;
|
||||
temp2 = temp;
|
||||
|
||||
int sum = temp2.a + temp2.b[2] + temp2.c;
|
||||
|
||||
return sum == 11;
|
||||
}
|
||||
20
examples/c/switch.c
Normal file
20
examples/c/switch.c
Normal file
@@ -0,0 +1,20 @@
|
||||
int main() {
|
||||
int a = 1;
|
||||
int b = 0;
|
||||
switch (a) {
|
||||
case 0: {
|
||||
b += 1;
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
b += 2;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
b += 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return b == 2;
|
||||
}
|
||||
9
examples/c/temp.c
Normal file
9
examples/c/temp.c
Normal file
@@ -0,0 +1,9 @@
|
||||
int fibonacci(int n) {
|
||||
while (n + n) {
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
return 1;
|
||||
}
|
||||
28
examples/c/temp2.c
Normal file
28
examples/c/temp2.c
Normal file
@@ -0,0 +1,28 @@
|
||||
struct color { int number; char name; };
|
||||
|
||||
int f(int i, int const a[i]) {
|
||||
int temp = 0;
|
||||
const float temp2 = 0.f, temp3 = 0.f;
|
||||
temp = sizeof(unsigned char);
|
||||
temp = _Alignof(unsigned char);
|
||||
|
||||
struct color c;
|
||||
c.name;
|
||||
struct color *cp = &c;
|
||||
cp->name;
|
||||
|
||||
for(int i = 0, j = 0; i < 10; ++i) {
|
||||
break;
|
||||
}
|
||||
|
||||
switch(temp) {
|
||||
case 1: {
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return temp;
|
||||
}
|
||||
11
examples/c/test.c
Normal file
11
examples/c/test.c
Normal file
@@ -0,0 +1,11 @@
|
||||
int main() {
|
||||
long int l = 1;
|
||||
long l2 = 2;
|
||||
long long l3 = 3;
|
||||
short int s = 4;
|
||||
short s2 = 5;
|
||||
int i = 6;
|
||||
char c = 7;
|
||||
|
||||
return (l + l2 + l3 + s + s2 + i + c) == 28;
|
||||
}
|
||||
5
examples/c/typecast.c
Normal file
5
examples/c/typecast.c
Normal file
@@ -0,0 +1,5 @@
|
||||
char temp = 0x00L;
|
||||
|
||||
int main(){
|
||||
return (temp = 0xEF36L) >= (2L);
|
||||
}
|
||||
10
examples/c/typedef.c
Normal file
10
examples/c/typedef.c
Normal file
@@ -0,0 +1,10 @@
|
||||
typedef int i32_t;
|
||||
typedef i32_t* p_i32_t;
|
||||
|
||||
int main() {
|
||||
i32_t a = 0;
|
||||
p_i32_t const b = &a;
|
||||
*b = 1;
|
||||
|
||||
return *b;
|
||||
}
|
||||
4
examples/c/unary.c
Normal file
4
examples/c/unary.c
Normal file
@@ -0,0 +1,4 @@
|
||||
int main() {
|
||||
unsigned char temp = 0x00L;
|
||||
return 1 > (--temp);
|
||||
}
|
||||
21
examples/c/while_continue_break.c
Normal file
21
examples/c/while_continue_break.c
Normal file
@@ -0,0 +1,21 @@
|
||||
int foo() {
|
||||
int sum = 0;
|
||||
int i = 0;
|
||||
|
||||
while(i < 10) {
|
||||
if(i == 3) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
sum += i;
|
||||
i++;
|
||||
|
||||
if(i == 5) break;
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
int main() {
|
||||
return foo() == 7;
|
||||
}
|
||||
Reference in New Issue
Block a user