This Post Contains A C++ Program To Find Areas Of 'X' Rectangles Stored In 2D-Array & Determining Largest & Smallest Area With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC3.0 Compiler & Will Help You To Understand The Concept Of '2D-Arrays', 'For-loop', 'If...else' & 'Nested Loops' From C++ Language. It Is A Well-Structured Program With Proper Comments Which Provides Step-By-Step Description Of Various Features Of The Language In A Simple
& Easy-To-Understand Way.
# Note : You Can Simply Copy-Paste The Following Program Or Code Into Compiler For Direct Result.
C++ Program To Find Areas Of 'X' Rectangles Stored In 2D-Array & Determining Largest & Smallest Area.
/* Header Files */
# include <iostream.h>
# include <conio.h>
# define Max 20
/* Main Program */
void main()
{
// Initialization Of Variables
int Num=0, i=0, j=0, k=0, a[Max][2], b[Max];
int Large=0, Small=0;
clrscr();
// Accepting No. Of Rect. From User
cout<<"\nEnter The No. Of Rectangles : ";
cin>>Num;
// Accepting The Dimensions Of 'N' Rect. From User
// & Storing Them In A 2D Array
cout<<"\nEnter The Dimensions Of "<<Num<<" Rectangles i.e Length & Breadth :";
cout<<"\n";
for(i=0;i<Num;i++)
{
for(j=0;j<2;j++)
{
cin>>a[i][j];
}
cout<<"\n";
}
// Calculating The Areas Of 'N' Rect. & Storing
// Them Into Another Array
j=0;
k=0;
for(i=0; i<Num; i++)
{
b[k] = a[i][j] * a[i][j+1];
k++; // Here 'k' Act As A Counter Variable
}
// Displaying The Array Which Contains The Areas
// Of 'N' Rect.
cout<<"\n\nThe Areas Of "<<Num<<" Rect. Are As Follows : ";
for(i=0; i<k; i++)
{
cout<<"\n\n"<<b[i];
}
cout<<"\n\n";
// Finding The Large & Small Area From 'N' Rect.
Large=b[0];
Small=b[0];
for(i=0; i<k; i++)
{
if(b[i] > Large)
Large = b[i];
if(b[i] < Small)
Small = b[i];
}
// Displaying The Large & Small Area Of Rect.
cout<<"\n\nLarge Area : "<<Large;
cout<<"\n\nSmall Area : "<<Small;
getch();
}
& Easy-To-Understand Way.
# Note : You Can Simply Copy-Paste The Following Program Or Code Into Compiler For Direct Result.
C++ Program To Find Areas Of 'X' Rectangles Stored In 2D-Array & Determining Largest & Smallest Area.
/* Header Files */
# include <iostream.h>
# include <conio.h>
# define Max 20
/* Main Program */
void main()
{
// Initialization Of Variables
int Num=0, i=0, j=0, k=0, a[Max][2], b[Max];
int Large=0, Small=0;
clrscr();
// Accepting No. Of Rect. From User
cout<<"\nEnter The No. Of Rectangles : ";
cin>>Num;
// Accepting The Dimensions Of 'N' Rect. From User
// & Storing Them In A 2D Array
cout<<"\nEnter The Dimensions Of "<<Num<<" Rectangles i.e Length & Breadth :";
cout<<"\n";
for(i=0;i<Num;i++)
{
for(j=0;j<2;j++)
{
cin>>a[i][j];
}
cout<<"\n";
}
// Calculating The Areas Of 'N' Rect. & Storing
// Them Into Another Array
j=0;
k=0;
for(i=0; i<Num; i++)
{
b[k] = a[i][j] * a[i][j+1];
k++; // Here 'k' Act As A Counter Variable
}
// Displaying The Array Which Contains The Areas
// Of 'N' Rect.
cout<<"\n\nThe Areas Of "<<Num<<" Rect. Are As Follows : ";
for(i=0; i<k; i++)
{
cout<<"\n\n"<<b[i];
}
cout<<"\n\n";
// Finding The Large & Small Area From 'N' Rect.
Large=b[0];
Small=b[0];
for(i=0; i<k; i++)
{
if(b[i] > Large)
Large = b[i];
if(b[i] < Small)
Small = b[i];
}
// Displaying The Large & Small Area Of Rect.
cout<<"\n\nLarge Area : "<<Large;
cout<<"\n\nSmall Area : "<<Small;
getch();
}
No comments:
Post a Comment