#include<iostream>
usingnamespace std;
int main()
{
int min, max, ave, sum, a, b, c;
cout<<"Enter 3 numbers: \n";
cin>>a;
cin>>b;
cin>>c;
if(a > b) && (a > c)
cout<<a<< "is the largest number \n";
else
{
if(b > a) && (b > c)
cout<<b<< "is the largest number \n";
else
cout<<c<< "is the largest number \n";
}
if(a < b) && (a < c)
cout<<a<< " is the minimum number \n";
else
{
if(b < a) && (b < c)
cout<<b<< "is the minimum number \n";
else
cout<<c<< "is the minimum number \n";
}
sum = a + b + c;
ave = sum / 3;
cout<<"The average of the 3 numbers is "<<ave<<" \n";
system("pause");
return 0;
}
#include<iostream>
usingnamespace std;
int main()
{
int min, max, ave, sum, a, array[a];
for(a=0;a<3;a++)
{
cout << "Enter number " << a+1 << " :";
cin >> array[a];
}
for(int x=0; x<2; x++)
{
for(int y=x; y<3; y++)
{
if(array[x]>array[y])
{
int temporal;
array[x]=temporal; //I swap the value of array[a] with array[b] using another parameter
array[x]=array[y];
array[y]=temporal;
}
}
}
//code added by me to check if the two loops worked well
min=array[0];
max=array[2];
cout << "The smallest number is: " << min << endl;
cout << "The gratest number is: " << max << endl;
sum = array[0]+array[1]+array[2];
ave = sum / 3;
cout<<"The average of the 3 numbers is "<<ave<<" \n";
system("pause");
return 0;
}
if((a > b) && (a > c))
{
cout<<a<< "is the largest number \n";
}
elseif((b > a) && (b > c))
{ cout<<b<< "is the largest number \n";}
else
{cout<<c<< "is the largest number \n";}
This is for max...
REMEMBER: ((b > a) && (b > c))
you can use "if" then "else if" and then "else"...
The "else" excludes even the first condition("else") even the second condition ("else if")
if((a > b) && (a > c))
{
cout<<a<< " is the largest number \n";
}
elseif((b > a) && (b > c))
{
cout<<b<< " is the largest number \n";
}
else
{
cout<<c<< " is the largest number \n";
}
if((a < b) && (a < c))
{
cout<<a<< " is the smallest number \n";
}
elseif((b < a) && (b < c))
{
cout<<b<< " is the smallest number \n";
}
else
{
cout<<c<< " is the smallest number \n";
}