#include <stdio.h>
int max_min;
void fn1( int n;int a[])
{ int i;
max=min=a[0];
for (i=0;i<n;i++)
{ if (a[i]>max)
max=a[i];
if (a[i]<min)
min=a[i];
}
}
int main()
{
int i;
int a[5]={2,3,4,5,6}
fn1 (5,a);
printf("max=%d",max);
printf("min=%d",min);
return 0;
}
#include <stdio.h> int max,min; int fn1( int n,int a[]) { int i; max=a[0]; min=a[0]; for (i=0;i<n;i++) { if (a[i]>max) max=a[i]; if (a[i]<min) min=a[i]; } } int main() { int i; int a[5]={2,3,4,5,6}; fn1 (5,a); printf("max=%d\n",max); printf("min=%d\n",min); return 0; }
大神,你的代码就是有点语法错误······“void fn1( int n;int a[])”分号换成逗号;“max=min=a[0];”不能连等;“ int a[5]={2,3,4,5,6}”语句结束加上分号;在编译器上写能帮你找错误~还有,注意缩进······
#include <stdio.h>
void ff(int n,int a[])
{ int i;
int max=a[0];
int min=a[0];
for(i=0;i<n;i++)
{ if(a[i]>max)
max=a[i];
if(a[i]<min)
min=a[i];
} printf("max=%d\n",max);
printf("min=%d\n",min);
}
int main()
{ int n,i;
int a[5]={2,3,4,5,6};
ff(5,a);
return 0;
}