C語言編寫的,可以參考。
#include<stdio.h>
#include<math.h>
void judge(float a,float b,float c)
{
float p;
if((((a+b)>c)&&(fabs(a-b)<c))||
(((b+c)>a)&&(fabs(b-c)<a))||
(((a+c)>b)&&(fabs(a-c)<b)))
printf("San jiao xing de bian chang shi : %f,%f,%f\n",a,b,c);
printf("San jiao xing de zhou chang shi : %f\n",a+b+c);
p=(a+b+c)/2;
printf("San jiao xing de mian ji shi : %f\n",sqrt(p*(p-a)*(p-b)*(p-c)));
}
else
printf("Error\n");
main()
float a,b,c;
int flag=0;
printf("Which do you wnat ?\n1 Creat a triangle.\n0 Exit\n");
scanf("%d",&flag);
while(flag==1)
printf("Please enter three bain chang :\n");
scanf("%f",&a);
scanf("%f",&b);
scanf("%f",&c);
judge(a,b,c);
printf("Which do you wnat ?\n1 Creat a triangle.\n2 Exit\n");
C語言編寫的,可以參考。
#include<stdio.h>
#include<math.h>
void judge(float a,float b,float c)
{
float p;
if((((a+b)>c)&&(fabs(a-b)<c))||
(((b+c)>a)&&(fabs(b-c)<a))||
(((a+c)>b)&&(fabs(a-c)<b)))
{
printf("San jiao xing de bian chang shi : %f,%f,%f\n",a,b,c);
printf("San jiao xing de zhou chang shi : %f\n",a+b+c);
p=(a+b+c)/2;
printf("San jiao xing de mian ji shi : %f\n",sqrt(p*(p-a)*(p-b)*(p-c)));
}
else
{
printf("Error\n");
}
}
main()
{
float a,b,c;
int flag=0;
printf("Which do you wnat ?\n1 Creat a triangle.\n0 Exit\n");
scanf("%d",&flag);
while(flag==1)
{
printf("Please enter three bain chang :\n");
scanf("%f",&a);
scanf("%f",&b);
scanf("%f",&c);
judge(a,b,c);
printf("Which do you wnat ?\n1 Creat a triangle.\n2 Exit\n");
scanf("%d",&flag);
}
}