From bde9255cf35820314e882969060f77f5cbd6c460 Mon Sep 17 00:00:00 2001 From: Rutherther Date: Sat, 11 Nov 2023 12:57:33 +0100 Subject: [PATCH] chore: load gcd parameters from memory --- programs/gcd.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/programs/gcd.c b/programs/gcd.c index 0b1f4a1..296b823 100755 --- a/programs/gcd.c +++ b/programs/gcd.c @@ -2,7 +2,12 @@ #include #endif -int int_remainder(int a, int b) { +int int_remainder(int a, int b) +{ + if (b == 0) { + return 0; + } + while (a >= b) { a -= b; } @@ -23,25 +28,30 @@ int gcd(int a, int b) return previous_r; } +#ifdef unix void main() { - int a = 1071; - int b = 462; - - #ifdef unix + int a, b; printf("a: "); scanf("%d", &a); printf("b: "); scanf("%d", &b); - #endif + int res = gcd(a, b); + printf("%d\n", res); +} +#else +void main() +{ + int* a_address = (int*)4; + int* b_address = (int*)8; + + int a = *a_address; + int b = *b_address; int res = gcd(a, b); - #ifdef unix - printf("%d\n", res); - #else int* result_address = 0; *result_address = res; - #endif - } +#endif + -- 2.48.1