-
1 Attachment(s)
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];
}
}
Attachment 12123
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'
-
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++; )
-
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.
-
I see what i did wrong thanks for the advice and sorry about the code tags :/ thanks again