How can I declare on top of my code a function that takes an array of ints as argument?
Thank you.

I get an error from this code below :

//Finding the minimum value in an array

#include <stdio.h>

int minimum (int values[10]);



int mimimum (int values[10])
{
	int minValue, i;
	
	minValue = values[0];
	
	for (i = 1; i < 10; ++i)
		if (values[i] < minValue)
			minValue = values[i];
	
	return minValue;
}


int main (int argc, const char * argv[]) {
    // insert code here...
    int scores[10], i, minScore;
	
	
	printf("Enter 10 scores\n");
	
	for (i = 0; i < 10; ++i)
		scanf("%i", &scores[i]);
	
	minScore = minimum(scores);
	printf("\nMinimum score is %i\n", minScore);
	
	return 0;
}

Am I doing something wrong?

Well, it'd look more like this:

#include <stdio.h>

int minimum (int values[]);



int mimimum (int values[])
{
    int minValue, i;

    minValue = values[0];

    for (i = 1; i < 9; ++i) /* Index starts at zero, zo 10 - 1 = 9 indexes. */
        if (values[i] < minValue)
            minValue = values[i];

    return minValue;
}


int main (int argc, const char * argv[]) {
    // insert code here...
    int scores[10], i, minScore;


    printf("Enter 10 scores\n");

    for (i = 0; i < 9; ++i) /* Index starts at 0, so 10 - 1 = 9 indexes. */
        scanf("%i", &scores[i]);

    minScore = minimum(scores);
    printf("\nMinimum score is %i\n", minScore);

    return 0;
}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.