write a program in c++ that takes four values in variables A,B,C,and D of type integer from the user find out the maximum Mid1? Mid2& minimum value and display them in sequence constraint : only use if /else vontrol structure
Answers
Answer:
class example
{
void minimum(int a,int b,int c,int d)
{
if(a<b)
{
if(a<c)
{
if(a<d)
{
System.out.println(a+" is minimum number among given four");
}
else
{
System.out.println(d+" is minimum number among given four");
}
}
else
{
if(c<d)
{
System.out.println(c+" is minimum number among given four");
}
else
{
System.out.println(d+" is minimum number among given four");
}
}
}
else
{
if(b<c)
{
if(b<d)
{
System.out.println(b+" is minimum number among given four");
}
else
{
System.out.println(d+" is minimum number among given four");
}
}
else
{
if(c<d)
{
System.out.println(c+" is minimum number among given four");
}
else
{
System.out.println(d+" is minimum number among given four");
}
}
}
}
void maximum_and_minimum(int a,int b,int c,int d)
{
if(a>b)
{
if(a>c)
{
if(a>d)
{
System.out.println(a+" is maximum number among given four");
}
else
{
System.out.println(b+" is maximum number among given four");
}
}
else
{
if(c>d)
{
System.out.println(c+" is maximum number among given four");
}
else
{
System.out.println(d+" is maximum number among given four");
}
}
}
else
{
if(b>c)
{
if(b>d)
{
System.out.println(b+" is maximum number among given four");
}
else
{
System.out.println(d+" is maximum number among given four");
}
}
else
{
if(c>d)
{
System.out.println(c+" is maximum number among given four");
}
else
{
System.out.println(d+" is maximum number among given four");
}
}
}
minimum(a,b,c,d);
}
public static void main(String args[])
{
example o1=new example();
o1.maximum_and_minimum(10,45,56,9);
}
}
Explanation:
int num, max, min;
printf ("Enter four numbers: ");
scanf ("%d", &num);
max = min = num;
for (int i = 0; i < 3; i++)
{
scanf ("%d", &num);
if (max < num)
max = num;
else if (min > num)
min = num;
}
printf ("The smallest and largest of given four numbers are %d and %d respectively.\n", min, max);
return 0;
}