ES6模板字串
阿新 • • 發佈:2021-02-14
技術標籤:c語言
輸入三角形的3條邊a,b,c,如果能構成一個三角形,輸出面積area和周長perimeter(保留2位小數)否則,輸出“These sides do not correspond to a valid triangle”。在一個三角形中,任意兩邊之和大於第三邊。(其中,P =(a+b+c)/2)
#include"stdio.h"
#include"math.h"
void main()
{
int a,b,c;
float p,s,x;
scanf("%d%d%d",&a,& b,&c);
if(a+b>c&&a+c>b&&b+c>a)
{
x=a+b+c;
p=x/2.0;
s=sqrt(p*(p-a)*(p-b)*(p-c));
printf("x=%.2f\ns=%.2f\n",x,s);
}
else
printf("These sides do not correspond to a valid triangle\n");
}