Thread: Max_Min Function

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    2

    Max_Min Function

    Hi ive been having some trouble with this program i have searched the forum and seen people making suggestion for this similar program however no of these suggestions work im almost finished with this and have a few errors that need correcting im currently using Microsoft Visual Studio 2010. here what i got Code:
    #include <stdio.h>


    #define N 10


    int max_min(int b[], int n, int *max, int *min)


    int main(void)
    {
    int a[N], i , big, small;


    printf("Enter %d numbers: \n", N);


    for( i = 0, i < N; i++; )
    scanf("%d", &a[i]);


    max_min(a, N, &big, &small);
    printf("Largest Number %d", big);
    printf("Smallest Number %d", small);


    return 0;
    }


    int max_min(int b[], int n, int *max, int *min)
    {
    int i;
    *max = *min = b[0];
    for( i = 1; i < n; i++ )
    {
    if(b[i] > *max){
    *max = b[i];
    }
    else if(b[i] < *min)
    *min = b[i];


    }
    }
    prat.c

    here are my errors:
    1>c:\microsoft visual studio 2010\projects\we\we\pratice.c(8): error C2085: 'main' : not in formal parameter list
    1>c:\microsoft visual studio 2010\projects\we\we\pratice.c(8): error C2143: syntax error : missing ';' before '{'
    1>c:\microsoft visual studio 2010\projects\we\we\pratice.c(25): error C2084: function 'int max_min(int *,int,int *,int *)' already has a body
    1>c:\microsoft visual studio 2010\projects\we\we\pratice.c(5) : see previous definition of 'max_min'

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    1. Welcome to the forums!
    2. From now on, be sure to post your code using code tags
    3. I don't see "#include <stdio.h>" at the top of your code

    Code:
    // This is a function declaration, and as such should be terminated with a semi-colon
    int max_min(int b[], int n, int *max, int *min)
    Code:
    // Your "for()" loop syntax is wrong.
    // There should be a semi-colon, not a comma, after the first argument
    // There should not be a semi-colon after the third argument
    
    for( i = 0, i < N; i++; )

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Since max min isn't returning anything, it should be a void function. You are changing max and min, and nothing else, and using pointers to do that. So nothing needs to be returned.

  4. #4
    Registered User
    Join Date
    Oct 2012
    Posts
    2
    I see what i did wrong thanks for the advice and sorry about the code tags :/ thanks again

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 09-07-2012, 04:35 AM
  2. Replies: 13
    Last Post: 03-20-2012, 08:29 AM
  3. Replies: 15
    Last Post: 06-09-2009, 02:19 AM
  4. Print function: sending a function.. through a function?
    By scarlet00014 in forum C Programming
    Replies: 3
    Last Post: 11-05-2008, 05:03 PM
  5. Replies: 9
    Last Post: 01-02-2007, 04:22 PM