3. Program to find out the area of triangle when three sides a, b and c of the triangle are given.

Chapter 4: 

Input And Output

Programming Exercise

Problem # 3:

Write a program to find out the area of triangle when three sides a, b and c of the
triangle are given. Use appropriate statements to input the values of a, b and c from the keyboard. Formula for the area of triangle is area =√s(s-a)(s-b)(s-c) where s = (a+b+c)/2.

Solution:

#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
int main(){
    float a,b,c,s,area;
    cout<<"Enter three sides of triangle:";
    cin>>a>>b>>c;
    s = (a+b+c)/2;
    area = sqrt(s*(s-a)*(s-b)*(s-c));
    cout<<"Area : "<<area<<endl;
    return 0;
}

Code Screenshot:

Chapter 4, Coding tutorial, Computer Science, CPP Basics, Exercise Solution, Input and Output, IT Series, Object Oriented Programming using C++, Programming for beginners, Programming Tutorial

Output:

Chapter 4, Coding tutorial, Computer Science, CPP Basics, Exercise Solution, Input and Output, IT Series, Object Oriented Programming using C++, Programming for beginners, Programming Tutorial


Let me know in the comment section if you have any question.

Previous Post:
2. Program that inputs radius of sphere from the user and calculate its volume and surface area.

Comments

Post a Comment