שאלה 2
Back Up Next

 

פתרון

/* 
  Module: tr3_q2.cpp
  Author: Yariv Amar
  What? This program sorts 3 numbers.
  Input :  3 integer numbers
  Output: the numbers in order
  Assumptions on input: Valid
  How?
  Algorithm: sorting data using Minimum & Maximum help fileds.
  find the max & min between first 2 numbers and then 
*/
#include <iostream.h>
void main()
{
	int Num1 , Num2 , Num3; //declering on numbers
	int Max,Min; //declering on help filed
	
	cout<<"Please enter 3 numbers:\n";
	cout<<"-----------------------\n";
	cin>>Num1>>Num2>>Num3;
	if(Num1>Num2) //find out the max & min form the 1st two,
	{
		Max=Num1; 
		Min=Num2;
	}
	else
	{
		Max=Num2;
		Min=Num1;
	}
	if (Max>Num3) //find out the 3rd nu. position.
	
		if (Num3<Min) 
		{
			cout<<"Used 3 conditions to arrange: ";
			cout<<Max<<","<<Min<<","<<Num3<<"\n";
		}
		else 
		{
			cout<<"Used 3 conditions to arrange: ";
			cout<<Max<<","<<Num3<<","<<Min<<"\n";
		}
	
	else
	{
		cout<<"Used 2 conditions to arrange: ";
		cout<<Num3<<","<<Max<<","<<Min<<"\n";
	}
}

פלטים מיצגים

פלט לדוגמה:

 

Back Up Next

 

© Copyright YAProductions 2000