[URI Online Judge] – 1043 – Triangle

Read three point floating values (A, B and C) and verify if is possible to make a triangle with them. If it is possible, calculate the perimeter of the triangle and print the message:
Perimetro = XX.X
If it is not possible, calculate the area of the trapezium which basis A and B and C as height, and print the message:
Area = XX.X


The input file has tree floating point numbers.


Print the result with one digit after the decimal point.

Sample Input Sample Output
6.0 4.0 2.0 Area = 10.0
6.0 4.0 2.1 Perimetro = 12.1


#include <cstdio>
#include <iostream>
using namespace std;
int main(){
 float a, b, c;
 cin >> a;
 cin >> b;
 cin >> c;
if (a < b + c && b < a + c && c < a + b){
 printf("Perimetro = %.1f\n", a + b + c);
 } else {
 printf("Area = %.1f\n", c * (a + b) / 2);
return 0;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s