From 9a849020118b9a07fb864b8ccdbfe56c6b5d3282 Mon Sep 17 00:00:00 2001 From: Alex Hirsch Date: Mon, 7 Jan 2019 13:24:22 +0100 Subject: [PATCH] Minor fixes for example inputs --- examples/empty/empty.mc | 2 +- examples/fem/fem.mc | 8 +-- examples/leibniz_pi/leibniz_pi.mc | 2 - examples/lucas_number/lucas_number.mc | 23 ++++--- examples/mandelbrot/mandelbrot.mc | 4 -- examples/number_guessing/number_guessing.mc | 12 ++-- examples/prime/prime.mc | 29 ++++----- examples/sorting_network/sorting_network.mc | 71 +++++++++++---------- examples/taylor/taylor.mc | 2 +- 9 files changed, 73 insertions(+), 80 deletions(-) diff --git a/examples/empty/empty.mc b/examples/empty/empty.mc index 905869d..a46866d 100644 --- a/examples/empty/empty.mc +++ b/examples/empty/empty.mc @@ -1,4 +1,4 @@ int main() { - return 0; + return 0; } diff --git a/examples/fem/fem.mc b/examples/fem/fem.mc index 5ece9fd..aae96f6 100644 --- a/examples/fem/fem.mc +++ b/examples/fem/fem.mc @@ -16,7 +16,7 @@ int main() if (Vbat < 0.0) { print("Please plug the battery in the right way"); print_nl(); - return; + return 1; } print("Resistor value: "); @@ -28,7 +28,7 @@ int main() if (R < 0.0 || C < 0.0) { print("Part values must be positive"); print_nl(); - return; + return 1; } print("Time step: "); @@ -47,7 +47,7 @@ int main() if (dt < 0.0 || iter < 0) { print("Cowardly refusing to go backwards in time"); print_nl(); - return; + return 1; } Vc = 0.0; @@ -68,5 +68,5 @@ int main() iter = iter - 1; } - return 0; + return 0; } diff --git a/examples/leibniz_pi/leibniz_pi.mc b/examples/leibniz_pi/leibniz_pi.mc index d641765..2891d66 100644 --- a/examples/leibniz_pi/leibniz_pi.mc +++ b/examples/leibniz_pi/leibniz_pi.mc @@ -1,12 +1,10 @@ float kth(float k) { - return 1.0 / (2.0 * k + 1.0); } int main() { - print("Please enter a number: "); float sign; diff --git a/examples/lucas_number/lucas_number.mc b/examples/lucas_number/lucas_number.mc index d0858f2..ddb9677 100644 --- a/examples/lucas_number/lucas_number.mc +++ b/examples/lucas_number/lucas_number.mc @@ -1,15 +1,14 @@ -void lucas_number (int x, int y, int num){ - int z; - z=0; - while(num >= x) - { - print_int(x); - print(", "); - z=x+y; - x=y; - y=z; - } - +void lucas_number (int x, int y, int num) +{ + int z; + z=0; + while(num >= x) { + print_int(x); + print(", "); + z=x+y; + x=y; + y=z; + } } int main() diff --git a/examples/mandelbrot/mandelbrot.mc b/examples/mandelbrot/mandelbrot.mc index fde05b6..b279b89 100644 --- a/examples/mandelbrot/mandelbrot.mc +++ b/examples/mandelbrot/mandelbrot.mc @@ -1,18 +1,14 @@ float transform_x(float x) { float fx; - fx = x; - return (-2.0) + ((1.0) - (-2.0)) * (fx / 80.0); } float transform_y(float y) { float fy; - fy = y; - return ((1.0) - ((1.0) - (-1.0)) * (fy / 50.0)) * 2.0; } diff --git a/examples/number_guessing/number_guessing.mc b/examples/number_guessing/number_guessing.mc index ef13446..881c8d9 100644 --- a/examples/number_guessing/number_guessing.mc +++ b/examples/number_guessing/number_guessing.mc @@ -1,30 +1,30 @@ /* Test booleans and greater/smaller comparisons */ + void guessNumber(int number, int max) { bool success; success = false; while(!success) { print("Enter a number between 0 and "); print_int(max); - print("\n"); + print("\n"); int guess; guess = read_int(); success = guess == number; - if(success) + if(success) print("you guessed correct"); else { - if(guess < number) + if(guess < number) print("the number is bigger\n"); - else + else print("the number is smaller\n"); } } print_nl(); } - + int main() { int test; test = 3; guessNumber(test, 10); return 0; } - diff --git a/examples/prime/prime.mc b/examples/prime/prime.mc index 18bbf43..e857c95 100644 --- a/examples/prime/prime.mc +++ b/examples/prime/prime.mc @@ -1,17 +1,16 @@ -int is_prime(int n){ - - int i; - i = 2; - int mod; - while (i < n/2) - { - mod = n - (n/i)*i; - if(mod == 0){ - return 0; - } - i = i +1; - } - return 1; +int is_prime(int n) +{ + int i; + i = 2; + int mod; + while (i < n / 2) { + mod = n - (n / i) * i; + if (mod == 0) { + return 0; + } + i = i + 1; + } + return 1; } int main() @@ -31,5 +30,5 @@ int main() print_int(result); print_nl(); - return 0; + return 0; } diff --git a/examples/sorting_network/sorting_network.mc b/examples/sorting_network/sorting_network.mc index 1e49aaf..0a06bfd 100644 --- a/examples/sorting_network/sorting_network.mc +++ b/examples/sorting_network/sorting_network.mc @@ -1,43 +1,44 @@ /* this example sorts 4 numbers like in an sorting network */ + void sort(int a, int b, int c, int d) { - int tmp; - if(a > c) { tmp = c; c = a; a = tmp; } - if(b > d) { tmp = d; d = b; b = tmp; } else {} - if(a > b) {tmp = b; b = a; a = tmp; } - if(c > d) { tmp = d; d = c; c = tmp; } - if(b > c) { tmp = c; c = b; b = tmp; } - print_int(a); print_int(b); print_int(c); print_int(d); print_nl(); + int tmp; + if(a > c) { tmp = c; c = a; a = tmp; } + if(b > d) { tmp = d; d = b; b = tmp; } else {} + if(a > b) {tmp = b; b = a; a = tmp; } + if(c > d) { tmp = d; d = c; c = tmp; } + if(b > c) { tmp = c; c = b; b = tmp; } + print_int(a); print_int(b); print_int(c); print_int(d); print_nl(); } int main() { - string info; info = "Enter a number which should be sorted within 1, 26 and 77:"; - print(info); print_nl(); - int a; a = read_int(); - int b; b = 26; - int c; c = 77; - int d; d = 1; + string info; info = "Enter a number which should be sorted within 1, 26 and 77:"; + print(info); print_nl(); + int a; a = read_int(); + int b; b = 26; + int c; c = 77; + int d; d = 1; - { - { - sort(a, b, c, d); - sort(a, b, d, c); - sort(a, c, b, d); - sort(a, c, d, b); - sort(c, b, a, d); - sort(c, b, d, a); - sort(b, c, d, a); - sort(b, c, a, d); - sort(b, a, c, d); - sort(b, a, d, c); - sort(b, d, a, c); - sort(b, d, c, a); - sort(d, a, b, c); - sort(d, a, c, b); - sort(d, c, a, b); - sort(d, b, a, c); - /* .*./. */ - } - } + { + { + sort(a, b, c, d); + sort(a, b, d, c); + sort(a, c, b, d); + sort(a, c, d, b); + sort(c, b, a, d); + sort(c, b, d, a); + sort(b, c, d, a); + sort(b, c, a, d); + sort(b, a, c, d); + sort(b, a, d, c); + sort(b, d, a, c); + sort(b, d, c, a); + sort(d, a, b, c); + sort(d, a, c, b); + sort(d, c, a, b); + sort(d, b, a, c); + /* .*./. */ + } + } - return 0; + return 0; } diff --git a/examples/taylor/taylor.mc b/examples/taylor/taylor.mc index 52c4b08..a4ec37b 100644 --- a/examples/taylor/taylor.mc +++ b/examples/taylor/taylor.mc @@ -38,5 +38,5 @@ int main() { print_float(pi); print_nl(); - return 0; + return 0; }