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;
}
#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:
Output:
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.
Thanks for ur help
ReplyDeleteThis comment has been removed by the author.
ReplyDelete