Area of Rectange, Right Angled Triangle and Circle
PROBLEM :
Calculate the area of rectangle, right angled triangle and circle.
Input:
The first line of the input contains T denoting the number of testcases. Then follows the description of testcase. Each testcase contains 5 space separated positive integers denoting the length of rectangle, width of rectangle, base of right angled triangle, perpendicular of right angled triangle and radius of circle respectively.
Output:
For each testcase, output a single line containing 3 space separated integers denoting the area of rectangle, area of right angled triangle, and area of circle respectively.
Note: We need to print the floor values of the areas. Also take value of pi = 3.14
Constraints:
1<=T<=50
1<=length / breadth / base / perpendicular / radius <= 100
Example:
Input:
1
32 32 54 12 52
Output:
1024 324 8490
--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------
#include<iostream>
using namespace std;
#include<math.h>
int main()
{
int t,RecL,RecW,TriB,TriP,CirR ;
cin>>t ;
while(t--)
{
cin>>RecL>>RecW ;
cin>>TriB>>TriP ;
cin>>CirR ;
// area of rectangle
cout<<RecL*RecW<<" " ;
// area of traingle
cout<<floor(0.5*TriB*TriP)<<" " ;
//area of circle
cout<<floor(3.14*CirR*CirR)<<" " ;
cout<<endl ;
}
return 0;
}
---------------------------------------------------------------------------------
Calculate the area of rectangle, right angled triangle and circle.
Input:
The first line of the input contains T denoting the number of testcases. Then follows the description of testcase. Each testcase contains 5 space separated positive integers denoting the length of rectangle, width of rectangle, base of right angled triangle, perpendicular of right angled triangle and radius of circle respectively.
Output:
For each testcase, output a single line containing 3 space separated integers denoting the area of rectangle, area of right angled triangle, and area of circle respectively.
Note: We need to print the floor values of the areas. Also take value of pi = 3.14
Constraints:
1<=T<=50
1<=length / breadth / base / perpendicular / radius <= 100
Example:
Input:
1
32 32 54 12 52
Output:
1024 324 8490
--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------
#include<iostream>
using namespace std;
#include<math.h>
int main()
{
int t,RecL,RecW,TriB,TriP,CirR ;
cin>>t ;
while(t--)
{
cin>>RecL>>RecW ;
cin>>TriB>>TriP ;
cin>>CirR ;
// area of rectangle
cout<<RecL*RecW<<" " ;
// area of traingle
cout<<floor(0.5*TriB*TriP)<<" " ;
//area of circle
cout<<floor(3.14*CirR*CirR)<<" " ;
cout<<endl ;
}
return 0;
}
---------------------------------------------------------------------------------
Comments
Post a Comment