Adding fortran C example for Shriya, bug #676
authorAndrey Miroshnikov <andrey@technepisteme.xyz>
Wed, 8 Nov 2023 16:17:59 +0000 (16:17 +0000)
committerAndrey Miroshnikov <andrey@technepisteme.xyz>
Wed, 8 Nov 2023 16:17:59 +0000 (16:17 +0000)
maxloc/Makefile [new file with mode: 0644]
maxloc/maxloc.c [new file with mode: 0644]

diff --git a/maxloc/Makefile b/maxloc/Makefile
new file mode 100644 (file)
index 0000000..813bab6
--- /dev/null
@@ -0,0 +1,10 @@
+.PHONY: all clean
+
+all: maxloc
+
+maxloc: maxloc.c
+       gcc maxloc.c -o maxloc
+       #gcc -Os -mno-vsx -mno-altivec maxloc.c -o maxloc
+
+clean:
+       rm -rf maxloc
diff --git a/maxloc/maxloc.c b/maxloc/maxloc.c
new file mode 100644 (file)
index 0000000..8d3d4a7
--- /dev/null
@@ -0,0 +1,36 @@
+#include<stdio.h>
+#include<limits.h>
+//#include<cornio.h>
+int m2(int * const restrict a, int n) 
+{ 
+       int m, nm; 
+       int i; 
+
+       m = INT_MIN; 
+       nm = -1; 
+       i=0; 
+       while (i<n) { 
+               while (i<n && a[i]<=m) 
+                       i++; 
+               if (a[i] > m) { 
+                       m = a[i]; 
+                       nm = i; 
+               } 
+               i++; 
+       } 
+       return nm; 
+}
+
+/*Testbench*/
+
+int main() 
+{
+
+       int arr[]= {5,2,8,1,3,7,9,4};
+       int size = sizeof(arr) / sizeof(arr[0]);
+       int result = m2(arr, size);
+
+       printf("Index of the maximum value in an array is: %d\n", result);
+       return 0;
+
+}