HI! I am a first year IT student and am facing a problem. I need to create a program that finds and prints the largest and smallest number of a series of 5 numbers inputted by the user. I already know how to use if, if-else, &&, and I could've used those but the challenge was to use only the single selection if statement so I had this program made:
Code:
#include <stdio.h>
#include <conio.h>
int main()
{
int a, b, c, d, e, min, max;
// Ask values from the user and put values to min and max
printf("Enter value of A: ");
scanf("%d", &a);
if(a<min)
min = a;
if(a>max)
max = a;
printf("Enter value of B: ");
scanf("%d",&b);
if(b<min)
min = b;
if(b>max)
max = b;
printf("Enter value of C: ");
scanf("%d", &c);
if(c<min)
min = c;
if(c>max)
max = c;
printf("Enter value of D: ");
scanf("%d", &d);
if(d<min)
min = d;
if(d>max)
max = d;
printf("Enter value of E: ");
scanf("%d", &e);
if(e<min)
min = e;
if(e>max)
max = e;
printf("Largest is: %d\n", max);
printf("Smallest is: %d\n", min);
getche();
}
but it seems to be missing something(probably) as it outputs a wrong max value. I would really appreciate if you could help me with it.
Thanks,
jrpet