C++ Control Flow Statements 5

Question:7
C++ program to take input for three number check and print lowest number?
Sol:
Method:1

#include<iostream>
using namespace std;
int main()
{
     int a,b,c;
     cout<<"Enter 3 nos ";
     cin>>a>>b>>c;
     if(a<b && a<c)
     cout<<"Min no = "<<a;
     else
       if(b<c)
       cout<<"Min no = "<<b;
       else
       cout<<"Min no = "<<c;
     return(0);
}
/* Output */
Enter 3 nos 78
25
4
Min no = 4

Method:2

#include<iostream>
using namespace std;
int main()
{
     int a,b,c,m;
     cout<<"Enter 3 nos ";
     cin>>a>>b>>c;
     if(a<b && a<c)
     m=a;
     else
       if(b<c)
       m=b;
       else
       m=c;
     cout<<"Min no = "<<m;
     return(0);
}

Method:3

#include<iostream>
using namespace std;
int main()
{
     int a,b,c,m;
     cout<<"Enter 3 nos ";
     cin>>a>>b>>c;
     m=a;
     if(b<m)
     m=b;
     if(c<m)
     m=c;
     cout<<"Min no = "<<m;

     return(0);
}

Method:4

#include<iostream>
using namespace std;
int main()
{
	int a,b,c,m;
	cout<<"Enter 3 nos ";
	cin>>a>>b>>c;
	m=(a<b && a<c)?a:(b<c)?b:c;
	cout<<"Min no = "<<m;

	return(0);
}

Question:8
C++ program to take input for three number check and print the following;
(i). Largest no
(ii). Lowest no
(iii). Difference between largest and lowest number
Sol:

#include<iostream>
using namespace std;
int main()
{
    int a,b,c,ma,mi,d;
    cout<<"Enter 3 nos ";
    cin>>a>>b>>c;
    // Max no
	if(a>b && a>c)
    ma=a;
    else
      if(b>c)
      ma=b;
      else
      ma=c;
    //Min no
    if(a<b && a<c)
    mi=a;
    else
      if(b<c)
      mi=b;
      else
      mi=c;
    
	cout<<"Max no = "<<ma<<endl;
	cout<<"Min no = "<<mi<<endl;
	//Diff
	d=ma-mi;
	cout<<"Diff = "<<d<<endl;
     return(0);
}
/* Output */
Enter 3 nos 65
97
25
Max no = 97
Min no = 25
Diff = 72