hello, i need help with this sub program, everything ele works fine except the subprogram that should compute the smallest and largest number in the array
#include<conio.h>
#include<stdio.h>
#define MAX 10
int input(void);
int range(int i,int *s1,int *s2,int *s3,int *l1,int *l2,int *l3,int f[MAX],int hf[MAX],int lf[MAX]);
void output(int v,int s1,int s2,int s3,int l1,int l2,int l3,int f[MAX],int hf[MAX],int lf[MAX]);
main()
{int f[MAX],lf[MAX],hf[MAX],i=0,n,a=0,b=0,v,s1,s2,s3,l1,l2,l3;
char choice, choice2;
clrscr();
do{
do{if(i==10)
{ printf("\n\n\t sorry,!!! this array is full " );
getch(); }
else{ n=input();
f[i]=n;
if(f[i] >=50 )
{ hf[a]=f[i];
a++; }
else
{ lf[b]=f[i];
b++; }
i++;
}
printf("\n exit ? (y/n) : ");
scanf(" %c",&choice );
}while(choice !='y' && choice!='Y' );
printf("\nsegregating/copying these numbers into two other arrays...."); printf("\n press any key to continue");
getch();
v=range(i,&s1,&s2,&s3,&l1,&l2,&l3,f,hf,lf);
output(v,s1,s2,s3,l1,l2,l3,f,hf,lf);
printf("\n\nexit (y) or repeat (n) ???? (y/n) :");
scanf(" %c",&choice2);
}while (choice2!='y' && choice2!='Y');
printf("\n\n\n\n\t\t\tterminating program >>>>>>>>>>.......");
getch();
}
int input(void)
{
int i;
printf("\n please enter a number : ");
scanf("%d",&i);
return i;
}
int range(int i,int *s1,int *s2,int *s3,int *l1,int *l2,int *l3,int f[MAX],int hf[MAX],int lf[MAX])
{int n,p,l=0,h=0,a,b,c,A,B,C;
for(p=0;p < i;p++)
{
if(f[i] >=50 )
{ h++; }
else
{ l++; }
}
for(p=1;p <= i;p++)
{
if(f[p] < f[p-1] )
a=f[p];
if(f[p-1] < f[p])
a=f[p-1];
if(f[p] >f[p-1])
A=f[p];
if(f[p-1] > f[p] )
A=f[p-1];
}
for(p=1;p <= h;p++)
{
if(hf[p] < hf[p-1])
b=hf[p];
if(hf[p-1] < hf[p] )
b=hf[p-1];
if(hf[p] > hf[p-1] )
B=hf[p];
if(hf[p-1] > hf[p] )
B=hf[p-1];
}
for(p=1;p <=l;p++)
{
if(lf[p] < lf[p-1])
c=lf[p];
if(lf[p-1] < lf[p])
c=lf[p-1];
if(lf[p] > lf[p-1])
C=lf[p];
if(lf[p-1] >lf[p] )
C=lf[p-1];
}
*s1=a;
*s2=b;
*s3=c;
*l1=A;
*l2=B;
*l3=C;
n=i;
return n;
}
void output(int v,int s1,int s2,int s3,int l1,int l2,int l3,int f[MAX],int hf[MAX],int lf[MAX])
{ int i,sum1=0,sum2=0,sum3=0,l=0,h=0;
float ave1,ave2,ave3;
for(i=0;i <= v;i++)
{ if(f[i] >=50)
h++;
else
l++; }
for(i=0;i <= v; i++ )
{ sum1+=f[i]; }
for(i=0;i <= h; i++ )
{ sum2+=hf[i];}
for(i=0;i <= l; i++)
{ sum3+=lf[i]; }
ave1=sum1/v;
ave2=sum2/h;
ave3=sum3/l;
printf("\n\t the numbers in array1 \n");
for(i=0; i < v;i++ )
{ printf("\t %d", f[i] ); }
printf("\n\t\t smallest number : %d",s1);
printf("\n\t\t largest number : %d",l1);
printf("\n\t\t sum : %d",sum1);
printf("\n\t\t average : %.2f",ave1);
printf("\n\t the numbers in array1 \n");
for(i=0; i < l;i++ )
{ printf("\t %d",lf[i] ); }
printf("\n\t\t smallest number : %d",s2);
printf("\n\t\t largest number : %d",l2);
printf("\n\t\t sum : %d",sum2);
printf("\n\t\t Average : %.2f", ave2);
printf("\n\t the numbers in array1 \n");
for(i=0; i < h;i++ )
{ printf("\t %d", hf[i] ); }
printf("\n\t\t Smallest number : %d",s3);
printf("\n\t\t Largest number : %d",l3);
printf("\n\t\t Sum : %d",sum3);
printf("\n\t\t Average : %.2f",ave3);
getch();
clrscr();
getch();
}
please help.