From 83b66a3036cb1a7dd28d4d3b9d7edfd7398c7624 Mon Sep 17 00:00:00 2001 From: Andrey Miroshnikov Date: Wed, 8 Nov 2023 16:17:59 +0000 Subject: [PATCH] Adding fortran C example for Shriya, bug #676 --- maxloc/Makefile | 10 ++++++++++ maxloc/maxloc.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 maxloc/Makefile create mode 100644 maxloc/maxloc.c diff --git a/maxloc/Makefile b/maxloc/Makefile new file mode 100644 index 00000000..813bab62 --- /dev/null +++ b/maxloc/Makefile @@ -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 index 00000000..8d3d4a7a --- /dev/null +++ b/maxloc/maxloc.c @@ -0,0 +1,36 @@ +#include +#include +//#include +int m2(int * const restrict a, int n) +{ + int m, nm; + int i; + + m = INT_MIN; + nm = -1; + i=0; + while (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; + +} -- 2.30.2