# Mean, Min, Max of N numbers without using array

This is a discussion on Mean, Min, Max of N numbers without using array within the C Programming forums, part of the General Programming Boards category; I am not sure how to determine a min and a max with my program. it finds the average but ...

1. ## Mean, Min, Max of N numbers without using array

I am not sure how to determine a min and a max with my program. it finds the average but is there a way i can also get it to print a min and max. here what i have so far

Code:
```int value;
int n;
int count;
int input_status;
float sum = 0, x, avg;

printf("\nEnter How Many Numbers : ");
scanf("%d", &n);

for(count = 1; count <= n; count++)
{
printf("x = ");
scanf("%f", &x);
sum += x;
}

avg = sum / n;```
printf("\nThe Average of Numbers is : %0.2f", avg);

2. Create a min variable and initialize it to the largest value possible for the type, create a max variable and initialize it to the smallest value possible for the type. Within the loop compare the values read in from the user to the values in these min/max variables and update as needed... if value from user is less than current min then update min, if value from user is more than current max then update max.

3. Originally Posted by hk_mp5kpdw
Create a min variable and initialize it to the largest value possible for the type, create a max variable and initialize it to the smallest value possible for the type.
..or set both to the first element the user inputs.

4. Code:
```if (count == 1)
{
min = x;
max = x;
}
else if (x < min)
min = x;
else if (x > max)
max = x;```
et voila...

5. Oh and btw, it's just a little detail. But it'd be better if you start your counter at 0 and let it loop while counter < n, everything in IT starts with 0...