difficulty sqrt()

Asked

Viewed 59 times

0

I need to calculate the area of a rectangle triangle but I cannot identify the error.

#include<stdio.h>
#include<math.h>
int main() 
{
 //declaracao de variaveis
 int a, b, c;
 int s;
 int s1, s2, s3;
 int total;
 int area;
 int sa, sb, sc;
 //inicio
 printf("digite 'a': ");
 scanf("%d", &a);

 printf("digite 'b': ");
 scanf("%d", &b);

 printf("digite 'c': ");
 scanf("%d", &c);

 s = (a + b + c) / (2);

 area = (s * (s - a) * s *(s - b) * s * (s - c);
 printf("\nAREA: %.2d", area);

 return(0);
  • In the variable area, you opened a parenthesis and did not close before the printf of the result.

  • The variable s, as well as area, shouldn’t be float?

  • My mistake, the variable should be float!

  • But it would be necessary to add the sqrt() command to the area variable and I don’t know how to do it ;(

2 answers

0

You can use sqrt directly in the printf

printf("\nAREA: %.2d", sqrt(area));

0

The area of a rectangular triangle can be calculated using the following formula: area = (base * height) / 2.

To have a better precision recommend using the double type.

#include <stdio.h>

int main() {
  printf("Qual é a base: ");
  double base = 0.0;
  scanf("%lf", &base);

  printf("Qual é a altura: ");
  double altura = 0.0;
  scanf("%lf", &altura);

  double area = (base * altura) / 2;

  printf("Área: %lf\n", area);

  return 0;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.