If else conditional statements.

Theory

You can use the same approach and generalize it for N numbers. All you need to do is start with largest as Integer.MIN_VALUE and smallest number as Integer.MAX_VALUE and loop through N numbers. At each iteration, compare the number with the largest and smallest number, if the current number is larger than the largest then it's a new largest, and if the current number is smaller than the smallest then it's a new smallest number.

Once you finish the iteration, you have the largest and smallest number without using an array. You can also assign the largest number as zero if there is no negative number in your input, but it won't work if the user can enter both negative and positive integers.

To make this program more interactive, you can accept all N numbers from the user from the command line by using Scanner. The user will keep entering an integer number on each iteration and you would be printing the largest and smallest number.

An if else statement in programming is a conditional statement that runs a different set of statements depending on whether an expression
is true or false. A typical if else statement would appear similar to the one below (this example is JavaScript, and would be very similar
in other C-style languages).
var x = 1;
if (x === 1) {
window.alert("The expression is true!");
}
else {
window.alert("The expression is false!");
}
In this case, with the variable x being equal to the number 1, the statement in the first set of curly braces {} is executed.
You would receive a pop-up "The expression is true!" alert message. If you were to change the first line of the above code to
var x = 42;, you would receive a pop-up alert message with the text "The expression is false!"




Example1: C program to find Largest and smallest among three numbers Using if else

void main()
{
int a,b,c, larg, small;
printf("Enter Three Number\n");
scanf("%d %d %d",&a,&b,&c);
if(a>b)
{
if(a>c)
larg = a;
else
larg = c;
}
else
{
if(b>c)
larg = b;
else
larg = c;
}
if(a {
if(a small = a;
else
small = c;
}
else
{
if(b small = b;
else
small = c;
}
printf("%d is largest number\n",larg);
printf("%d is Smallest Number ",small);
return 0;
}

Example 2: Using only if statements to find the largest number.

int main()
{
int A, B, C;
printf("Enter the numbers A, B and C: ");
scanf("%d %d %d", &A, &B, &C);
if (A >= B && A >= C)
printf("%d is the largest number.", A);
if (B >= A && B >= C)
printf("%d is the largest number.", B);
if (C >= A && C >= B)
printf("%d is the largest number.", C);
return 0;
}