From d7241876642935d3b2d9de2f61b968eb140dc035 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Wed, 15 Nov 2023 14:17:09 +0000 Subject: [PATCH] python conversion of maxloc.c --- maxloc/maxloc.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 maxloc/maxloc.py diff --git a/maxloc/maxloc.py b/maxloc/maxloc.py new file mode 100644 index 00000000..bb260d25 --- /dev/null +++ b/maxloc/maxloc.py @@ -0,0 +1,25 @@ +def m2(a): + m = 0; + nm = -1; + i = 0; + n = len(a) + + while (i m) : + print("%d idx %d > m %d" % (i, a[i], m)) + m = a[i] + nm = i + i += 1 + return nm; + +# /*Testbench*/ + +if __name__ == '__main__': + arr = [5,2,8,1,3,7,9,4] + print("search list", arr) + result = m2(arr) + + print("Index of the maximum value in an array is: %d" % result) -- 2.30.2