Assignments » Flow Of Control » Set1 » Solution 5

If the ages of Ram, Sulabh and Ajay are input by the user, write a program to determine the youngest of the three.

 


#include<iostream>
using namespace std;

int main()
{
	int ram_age,sulabh_age,ajay_age;
	cout<<"Enter Ram age:";
	cin>>ram_age;
	cout<<"Enter Sulabh age:";
	cin>>sulabh_age;
	cout<<"Enter Ajay age:";
	cin>>ajay_age;

	if (ram_age<sulabh_age && ram_age<ajay_age)
		cout<<"Ram is youngest";
	else if(sulabh_age<ram_age && sulabh_age<ajay_age)
		cout<<"Sulabh is youngest";
	else
		cout<<"Ajay is youngest";


	return 0;
}

 

 

SAMPLE RUN # 1

Enter Ram age:45
Enter Sulabh age:34
Enter Ajay age:22
Ajay is youngest

SAMPLE RUN # 2

Enter Ram age:45
Enter Sulabh age:34
Enter Ajay age:39
Sulabh is youngest

SAMPLE RUN # 3

Enter Ram age:25
Enter Sulabh age:34
Enter Ajay age:29
Ram is youngest