So, I'm new to C and I'm trying to write a program that finds the max value and prints the index. My code should be working however when I run it the output looks like this:
Testing program...
The Array :
The greatest of 12 values is 0 at index 0
End of program...Goodbye!
Can somebody tell me why it prints zero for the value and index.
Thanks!
int find_index_of_max(float [], int, int, int, int);
void strappend(char [], char []);
int main (int argc, const char * argv[]) {
printf("Testing program...\n");
//variable definition
float arr[] = {1, 22, 13, 5, 7, 10, 2, 9, 6 , 12, 14, 27};
int size = sizeof arr / sizeof arr[0];
int i;
int k;
printf("\nThe Array :\n");
printf("The greatest of %d values is %d at index %d\n", size, i, k);
printf("\nEnd of program...Goodbye!");
return 0;
}
#include "Funcs.h"
int find_index_of_max(float arr[], int size, int i, int j, int k)
{
i, j, k = 0;
i = arr[0];
for (j = 1; j < size; ++j)
if (arr[j] > i) {
i = arr[j];
k = j;
}
return i, k;
}

New Topic/Question
Reply




MultiQuote





|