top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

C++ program to find out the area of square, rectangle and triangle?

+1 vote
93 views
C++ program to find out the area of square, rectangle and triangle?
posted Feb 1 by Gutu Kitessa

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

0 votes
#include<iostream>
using namespace std;
int area(int);
int area(int,int);
float area(float);
float area(float,float);
int main()
{
    int s,l,b;
    float bs,ht;
    cout<<"Enter side of a square:";
    cin>>s;
    cout<<"Enter length and breadth of rectangle:";
    cin>>l>>b;
    cout<<"Enter base and height of triangle:";
    cin>>bs>>ht;
    cout<<"Area of square is"<<area(s);
    cout<<"\nArea of rectangle is "<<area(l,b);
    cout<<"\nArea of triangle is "<<area(bs,ht);
}
int area(int s)
{
    return(s*s);
}
int area(int l,int b)
{
    return(l*b);
}
float area(float bs,float ht)
{
   return((bs*ht)/2);
}

Sample Input
Enter side of a square:2
Enter length and breadth of rectangle:3 6
Enter base and height of triangle:4 4

Sample Output
Area of square is4
Area of rectangle is 18
Area of triangle is 8

answer Feb 2 by Salil Agrawal
0 votes
#include<iostream>

using namespace std;

int main()
{
   int s,l,b,bs,ht;

    int SquareArea,RectangleArea,TriangleArea;

    cout<<"Enter the side";
    cin>>s;
    SquareArea= s*s;
    cout<<"\nArea of the square is:"<<SquareArea;

    cout<<"\nEnter length and breadth";
    cin>>l;
    cin>>b;
    RectangleArea=l*b;
    cout<<"\nArea of the Rectangle is:"<<RectangleArea;

    cout<<"\nEnter base and height for triangle";
    cin>>bs>>ht;
    TriangleArea=((bs*ht)/2);
    cout<<"\nArea of the Triangle is:"<<TriangleArea;

    return 0;
}
answer Mar 20 by Drasti Chavda
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...