C++ program to find area of a triangle and a square using function overloading

#include <iostream>
#include <math.h>
using namespace std;
float area(float a,float b,float c)
{
    float s=(a+b+c)/2.0;
    float ar=sqrt(s*(s-a)*(s-b)*(s-c));
    return ar;
}
float area(float l)
{
    float ar=l*l;
    return ar;
}

int main()
{
    float a,b,c,l;
    cout<<"Enter sides of a triangle: ";
    cin>>a>>b>>c;
    cout<<"Enter length of a square: ";
    cin>>l;
    cout<<endl<<"Area of triangle is "<<area(a,b,c);
    cout<<endl<<"Area of square is "<<area(l);
    return 0;
}

No comments:

Post a Comment