Go to Home Page

/*******************************************************************************
Problem: The area of a rectangular garden is given by the expresion:
Area = X(30-2X) X belongs[2,12] X is integer
Write a program that show a table with the X values vs Area values
and also the program should output the maximun Area and the X value
for that maximun Area.

Example of Output:
     X          Area
    ---        ------
     2            52
     3            72
     4            88
      .             ..
      .             ..
      .             ..
    12           72

Maximun Area = 112
X value for maximun Area = 7

Course: C++
Tutor : Guillermo Julca
Mercy College

View Output
******************************************************************************/
//---------------------------------------------------------------------------
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
#pragma hdrstop

 

//---------------------------------------------------------------------------

#pragma argsused
int main(int argc, char* argv[])
{
cout.setf(ios::fixed);
//cout.setf(ios::showpoint);
cout.precision(0);
int x;
double Area,MaxArea,MaxX;
cout<<" X"<<setw(10)<<"Area"<<endl;
cout<<"---"<<setw(10)<<"------"<<endl;
MaxArea = 0;
for(x= 2; x<=12;x++)
{
Area = x*(30 - 2*x);
cout<<setw(2)<<x<<setw(9)<<Area<<endl;
if (Area > MaxArea)
{
MaxArea = Area;
MaxX = x;
} // end if (Area > MaxArea)
} // end for(x= 2; x<=12;x++)
cout<<endl;
cout<<"Maximun Area = "<<MaxArea<<endl;
cout<<"X value for maximun Area = "<<MaxX<<endl;
getchar();
return 0;
}

View Output
//---------------------------------------------------------------------------

Back to Home Page



Copyright  © 2002                                   GJ  GUILLERMO JULCA