# Thread: Program to find the largest and lowest value

1. ## Program to find the largest and lowest value

I am trying to write a C program that can accept 10 numbers between 1 and 100. If values outside the range are entered an error message should be displayed and allow the user to enter a correct value. It should then find the highest value entered and lowest value entered.

Here is what i have tried so far but i get the output "All numbers must be between 1 to 100". Kindly assist.

Here is my code:

Code:
```#include "stdio.h"

int main() {
int num1, num2, num3, num4, num5, num6, num7, num8, num9, num10;

printf("\nEnter the first number : ");
scanf("%d", &num1);

printf("\nEnter the second number : ");
scanf("%d", &num2);

printf("\nEnter the third number : ");
scanf("%d", &num3);

printf("\nEnter the fourth number : ");
scanf("%d", &num4);

printf("\nEnter the fifth number : ");
scanf("%d", &num5);

printf("\nEnter the sixth number : ");
scanf("%d", &num6);

printf("\nEnter the seventh number : ");
scanf("%d", &num7);

printf("\nEnter the eighth number : ");
scanf("%d", &num8);

printf("\nEnter the nineth number : ");
scanf("%d", &num9);

printf("\nEnter the tenth number : ");
scanf("%d", &num10);

if ((num1 < 1 &&  num2 < 1 &&  num3 < 1 &&  num4 < 1 &&  num5 < 1 &&  num6 < 1 &&  num7 < 1 &&  num8 < 1 &&  num9 < 1 &&  num10 < 1) &&
(num1 > 100 &&  num2 > 100 &&  num3 > 100 &&  num4 > 100 &&  num5 > 100 &&  num6 > 100 &&  num7 > 100 &&  num8 > 100 &&  num9 > 100 &&  num10 > 100)){

if( num1>=num2 && num1>=num3 && num1>=num3 && num1>=num4 && num1>=num5 && num1>=num6 && num1>=num7 && num1>=num8 && num1>=num9 && num1>=num10)
printf("%d.2lf is the largest number.", num1);
else if( num1<=num2 && num1<=num3 && num1<=num3 && num1<=num4 && num1<=num5 && num1<=num6 && num1<=num7 && num1<=num8 && num1<=num9 && num1<=num10)
printf("%d.2lf is the smallest number.", num1);

else if( num2>=num1 && num2>=num3 && num2>=num3 && num2>=num4 && num2>=num5 && num2>=num6 && num2>=num7 && num2>=num8 && num2>=num9 && num2>=num10)
printf("%d.2lf is the largest number.", num2);
else if( num2<=num1 && num2<=num3 && num2<=num3 && num2<=num4 && num2<=num5 && num2<=num6 && num2<=num7 && num2<=num8 && num2<=num9 && num2<=num10)
printf("%d.2lf is the largest number.", num2);

else if( num3>=num1 && num3>=num2 && num3>=num4 && num3>=num5 && num3>=num6 && num3>=num7 && num3>=num8 && num3>=num9 && num3>=num10)
printf("%d.2lf is the largest number.", num3);
else if( num3<=num1 && num3<=num2 && num3<=num4 && num3<=num5 && num3<=num6 && num3<=num7 && num3<=num8 && num3<=num9 && num3<=num10)
printf("%d.2lf is the largest number.", num3);

else if( num4>=num1 && num4>=num2 && num4>=num3 && num4>=num5 && num4>=num6 && num4>=num7 && num4>=num8 && num4>=num9 && num4>=num10)
printf("%d.2lf is the largest number.", num4);
else if( num4<=num1 && num4<=num2 && num4<=num3 && num4<=num5 && num4<=num6 && num4<=num7 && num4<=num8 && num4<=num9 && num4<=num10)
printf("%d.2lf is the largest number.", num4);

else if( num5>=num1 && num5>=num2 && num5>=num3 && num5>=num4 && num5>=num6 && num5>=num7 && num5>=num8 && num5>=num9 && num5>=num10)
printf("%d.2lf is the largest number.", num5);
else if( num5<=num1 && num5<=num2 && num5<=num3 && num5<=num4 && num5<=num6 && num5<=num7 && num5<=num8 && num5<=num9 && num5<=num10)
printf("%d.2lf is the largest number.", num5);

else if( num6>=num1 && num6>=num2 && num6>=num3 && num6>=num4 && num6>=num5 && num6>=num7 && num6>=num8 && num6>=num9 && num6>=num10)
printf("%d.2lf is the largest number.", num6);
else if( num6<=num1 && num6<=num2 && num6<=num3 && num6<=num4 && num6<=num5 && num6<=num7 && num6<=num8 && num6<=num9 && num6<=num10)
printf("%d.2lf is the largest number.", num6);

else if( num7>=num1 && num7>=num2 && num7>=num3 && num7>=num4 && num7>=num5 && num7>=num6 && num7>=num8 && num7>=num9 && num7>=num10)
printf("%d.2lf is the largest number.", num7);
else if( num7<=num1 && num7<=num2 && num7<=num3 && num7<=num4 && num7<=num5 && num7<=num6 && num7<=num8 && num7<=num9 && num7<=num10)
printf("%d.2lf is the largest number.", num7);

else if( num8>=num1 && num8>=num2 && num8>=num3 && num8>=num4 && num8>=num5 && num8>=num6 && num8>=num7  && num8>=num9 && num8>=num10)
printf("%d.2lf is the largest number.", num8);
else if( num8<=num1 && num8<=num2 && num8<=num3 && num8<=num4 && num8<=num5 && num8<=num6 && num8<=num7  && num8<=num9 && num8<=num10)
printf("%d.2lf is the largest number.", num8);

else if( num9>=num1 && num9>=num2 && num9>=num3 && num9>=num4 && num9>=num5 && num9>=num6 && num9>=num7 && num9>=num8 && num9>=num10)
printf("%d.2lf is the largest number.", num9);
else if( num9<=num1 && num9<=num2 && num9<=num3 && num9<=num4 && num9<=num5 && num9<=num6 && num9<=num7 && num9<=num8 && num9<=num10)
printf("%d.2lf is the largest number.", num9);

else if( num10>=num1 && num10>=num2 && num10>=num3 && num10>=num4 && num10>=num5 && num10>=num6 && num10>=num7 && num10>=num8 && num10>=num9)
printf("%d.2lf is the largest number.", num10);
else( num10<=num1 && num10<=num2 && num10<=num3 && num10<=num4 && num10<=num5 && num10<=num6 && num10<=num7 && num10<=num8 && num10<=num9);
printf("%d.2lf is the largest number.", num10);

}else{
printf("All numbers must be between 1 to 100");
}

return (0);
}```

2. > int num1, num2, num3, num4, num5, num6, num7, num8, num9, num10;

int num[10];

Then replace your copy/paste of input with
Code:
```for ( i = 0 ; i < 10 ; i++ ) {
printf("\nEnter the %d number : ",i+1);
scanf("%d", num[i]);
}```
You can then do a similar loop to find min/max within the array.

3. Originally Posted by Salem
> int num1, num2, num3, num4, num5, num6, num7, num8, num9, num10;

int num[10];

Then replace your copy/paste of input with
Code:
```for ( i = 0 ; i < 10 ; i++ ) {
printf("\nEnter the %d number : ",i+1);
scanf("%d", num[i]);
}```
You can then do a similar loop to find min/max within the array.
Can you explain a little more ?

4. Code:
```#include <stdio.h>
int main()
{
int i, sayi[5], max = 0;

for(i = 0; i < 5; i++)
{
printf("Lutfen %d. sayiyi girin.\n", i);
scanf("%d", &sayi[i]);

if(sayi[i] >= max)
{
max = sayi[i];
}
else
{
max = max;
}
}
printf("max sayi : %d\n", max);

return 0;
}```

5. Originally Posted by Mavi
Can you explain a little more ?
This might help

For, While and Do While Loops in C - Cprogramming.com

https://www.cprogramming.com/tutorial/c/lesson8.html

6. Originally Posted by Click_here
Thank you bro.