Hi,
I'm having difficulty writing a c program that asks the user to input 4 integers and it find the smallest and largest integer. I can only use 4 "if" statements to complete the program. I know the program does not compute the smallest integer correctly, but how can i fix it ? This is what I have so far..
Code:
#include <stdio.h>
int main()
{
int num1, num2, num3, num4;
int smallest, largest;
printf("Enter four integers: ");
scanf("%d %d %d %d", &num1, &num2, &num3, &num4);
smallest = num1;
if (num1 >= num2)
if (num1 >= num3)
if (num1 >= num4)
largest = num1;
else
largest = num4;
else if (num4 >= num3)
largest = num4;
else
largest = num3;
else
largest = num2;
printf("Largest: %d\n", largest);
printf("Smallest: %d\n", smallest);
return 0;
}