tam giác TỆP
#include<stdio.h>
#include<math.h>
struct DIEM
{
int x,y;
} A,B,C;
float khoangcach(DIEM a,DIEM b)
{
return sqrt(((a.x-b.x)*(a.x-b.x))+((a.y-b.y)*(a.y-b.y)));
}
int tamgiac(DIEM a,DIEM b,DIEM c)
{
float c1,c2,c3;
c1=khoangcach(a,b);
c2=khoangcach(b,c);
c3=khoangcach(a,c);
if(c1+c2<=c3) return 0;
if(c1+c3<=c2) return 0;
if(c3+c2<=c1) return 0;
return 1;
}
main()
{
FILE *f;
DIEM A,B,C;
f=fopen("diem.txt","r");
if(f!=NULL)
{
fscanf(f,"%d%d",&A.x,&A.y);
fscanf(f,"%d%d",&B.x,&B.y);
fscanf(f,"%d%d",&C.x,&C.y);
}
fclose(f);
f=fopen("kq.txt","w");
fprintf(f,"
toa do diem A(%d,%d)",A.x,A.y);
fprintf(f,"
toa do diem B(%d,%d)",B.x,B.y);
fprintf(f,"
toa do diem C(%d,%d)",C.x,C.y);
fprintf(f,"
khoang cach 2 diem A, B la: %f",khoangcach(A,B));
fprintf(f,"
khoang cach 2 diem C,B la: %f",khoangcach(C,B));
fprintf(f,"
khoang cach 2 diem A, C la: %f",khoangcach(A,C));
if(tamgiac(A,B,C)==1) fprintf(f,"
tao thanh 1 tam giac");
else fprintf(f,"
ko tao thanh tam giac");
fclose(f);
}
Bạn đang đọc truyện trên: TruyenTop.Vip