본문 바로가기

Goorm_C

[구름LEVEL][C] - 삼각형의 넓이 2

#include <stdio.h>
#include <math.h>
int main() {
	float a,b,c,s,S;
	scanf("%f %f %f",&a,&b,&c);
	s=(a+b+c)/2;
	S=sqrt(s*(s-a)*(s-b)*(s-c));
	printf("%.2f",S);
	return 0;
}

sqrt 함수 = 제곱근 => <math.h> 헤더파일 사용

 

헤론의 공식 : 길이가 a, b, c인 삼각형에서

s = (a+b+c)/2 이고

S = root( s(s-a)(s-b)(s-c) )