C++ Program to Calculate Perimeter and Area

 C++ Program to Calculate Perimeter and Area


source code : 

//Perimeter and Area of Triangle,Rectangle,Square and Circle
#include<iostream>
#include<math.h>
using namespace std;

int main(){
     cout<<"********Lets code for Triangle ********"<<endl;
    float a,b,c,perimeter,sp,area;
    cout<<"Enter the sides of triangle : ";
    cin>>a>>b>>c;
    perimeter= a+b+c;
    cout<<"Perimeter of triangle is : "<<perimeter<<endl;
    sp=perimeter/2;
    area = sqrt(sp*(sp-a)*(sp-b)*(sp-c));
    cout<<"Area of triangle is : "<<area<<endl;

    cout<<"*************Lets code for Rectangle******"<<endl;
    float length,breadth,p,ar;
    cout<<"Enter the length and breadth of rectangle : ";
    cin>>length>>breadth;
    p= 2*(length+breadth);
    cout<<"Perimeter of rectangle is : "<<p<<endl;
    ar=length*breadth;
    cout<<"Area of rectangle is : "<<ar<<endl;

    cout<<"*********Lets code for square*******"<<endl;
    float d;
    cout<<"Enter the side of square : ";
    cin>>d;
    float e,f;
    e=4*d;
    cout<<"Perimeter of square is : "<<e<<endl;
    f=d*d;
    cout<<"Area of square is : "<<f<<endl;

    cout<<"********Lets code for circle*******"<<endl;
    float r,pi=3.14,C,A;
    cout<<"Enter the radius of circle : ";
    cin>>r;
    C= 2*pi*r;
    cout<<"Circumference of circle is : "<<C<<endl;
    A= pi*r*r;
    cout<<"Area of Circle is : "<<A<<endl;

    return 0;
}
Previous
Next Post »