0% found this document useful (0 votes)
8 views

2 CPP

The document defines functions to calculate properties of triangles such as checking if three points form a triangle, calculating angles, midsegments, altitudes, and area. It takes in x,y coordinates of three points, calculates side lengths, and calls functions to output various triangle properties.

Uploaded by

n23dcci080
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

2 CPP

The document defines functions to calculate properties of triangles such as checking if three points form a triangle, calculating angles, midsegments, altitudes, and area. It takes in x,y coordinates of three points, calculates side lengths, and calls functions to output various triangle properties.

Uploaded by

n23dcci080
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <stdio.

h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#define PI 3.1415
float canhAB, canhBC, canhCA;
bool kiemtra_tamgiac(float A[],float B[],float C[]);
void goccanh_tamgiac(float A[],float B[],float C[],float canhAB,float canhBC,float
canhCA);
void trungtuyen_tamgiac (float A[],float B[],float C[],float canhAB,float
canhBC,float canhCA);
void duongcao_tamgiac(float A[],float B[],float C[],float canhAB,float canhBC,float
canhCA);
void dientich_tamgiac(float A[],float B[],float C[],float canhAB,float canhBC,float
canhCA);
int main(){
float A[2]={1,1};
float B[2]={2,2};
float C[2]={3,1};
float canhAB = sqrt(pow(A[0]-B[0],2)+pow(A[1]-B[1],2));
float canhBC = sqrt(pow(B[0]-C[0],2)+pow(B[1]-C[1],2));
float canhCA = sqrt(pow(C[0]-A[0],2)+pow(C[1]-A[1],2));
printf("Nhap toa do diem A: \n");
printf("Ax: %.0f\n",A[0]);
printf("Ay: %.0f\n",A[1]);
printf("Nhap toa do diem B: \n");
printf("Bx: %.0f\n",B[0]);
printf("By: %.0f\n",B[1]);
printf("Nhap toa do diem B: \n");
printf("Cx: %.0f\n",C[0]);
printf("Cy: %.0f\n",C[1]);
printf("\nToa do diem A da nhap: A(%.2f, %.2f)",A[0],A[1]);
printf("\nToa do diem B da nhap: B(%.2f, %.2f)",B[0],B[1]);
printf("\nToa do diem C da nhap: C(%.2f, %.2f)",C[0],C[1]);
kiemtra_tamgiac(A,B,C);
goccanh_tamgiac(A,B,C,canhAB,canhBC,canhCA);
duongcao_tamgiac(A,B,C,canhAB,canhBC,canhCA);
trungtuyen_tamgiac(A,B,C,canhAB,canhBC,canhCA);
dientich_tamgiac(A,B,C,canhAB,canhBC,canhCA);
return 0;
}
bool kiemtra_tamgiac(float A[],float B[],float C[]){
bool kiemtra;
float lenAB = sqrt(pow(A[0]-B[0],2)+pow(A[1]-B[1],2));
float lenBC = sqrt(pow(C[0]-B[0],2)+pow(C[1]-B[1],2));
float lenAC = sqrt(pow(A[0]-C[0],2)+pow(A[1]-C[1],2));
if(lenAB+lenBC>lenAC && lenAB+lenAC>lenBC && lenBC+lenAC>lenAB){
kiemtra=true;
printf("\n\n==> Toa do ba diem nhap vao tao thanh mot tam giac\n");
}else{
kiemtra=false;
printf("==> Toa do ba diem nhap vao khong tao thanh tam giac\n");
} return kiemtra;
}
void goccanh_tamgiac(float A[],float B[],float C[],float canhAB,float canhBC,float
canhCA){
printf("\n\nChieu dai cac canh cua tam giac: \n");
printf("Chieu dai canh AB: %.2f\n",canhAB);
printf("Chieu dai canh BC: %.2f\n",canhBC);
printf("Chieu dai canh CA: %.2f\n\n",canhCA);
float gocA =
acos((pow(canhAB,2)+pow(canhCA,2)-pow(canhBC,2))/(2*canhAB*canhCA))*(180/PI);
printf("\n\nSo do cac goc cua tam giac: \n");
printf("Goc A: %.2f\n",gocA );
float gocB =
acos((pow(canhAB,2)+pow(canhBC,2)-pow(canhCA,2))/(2*canhBC*canhAB))*(180/PI);
printf("Goc B: %.2f\n",gocB );
float gocC = 180- gocA - gocB;
printf("Goc C: %.2f\n",gocC );
}
void trungtuyen_tamgiac (float A[],float B[],float C[],float canhAB,float
canhBC,float canhCA){
float ttA,ttB,ttC;
ttA = sqrt(2*pow(canhCA,2)+ 2*pow(canhBC,2)-pow(canhAB,2))/2;
printf("Do dai trung tuyen tu dinh A: %.2f\n",ttA);
ttB = sqrt(2*pow(canhAB,2)+ 2*pow(canhBC,2)-pow(canhCA,2))/2;
printf("Do dai trung tuyen tu dinh B: %.2f\n",ttB);
ttC = sqrt(2*pow(canhCA,2)+ 2*pow(canhAB,2)-pow(canhBC,2))/2;
printf("Do dai trung tuyen tu dinh C: %.2f\n",ttC);
}
void duongcao_tamgiac(float A[],float B[],float C[],float canhAB,float canhBC,float
canhCA){
float s=(canhAB+canhBC+canhCA)/2;
float heSo=sqrt(s*(s-canhAB)*(s-canhBC)*(s-canhCA));
printf("\n\nSo do nang cao tam giac ABC \n");
float dcA = (2*heSo)/canhAB;
float dcB = (2*heSo)/canhCA;
float dcC = (2*heSo)/canhBC;
printf("Do dai duong cao tu dinh A: %.2f\n",dcA);
printf("Do dai duong cao tu dinh B: %.2f\n",dcB);
printf("Do dai duong cao tu dinh C: %.2f\n",dcC);
}
void dientich_tamgiac(float A[],float B[],float C[],float canhAB,float canhBC,float
canhCA){
float s=(canhAB+canhBC+canhCA)/2;
float heSo=sqrt(s*(s-canhAB)*(s-canhBC)*(s-canhCA));
float dcA = (2*heSo)/canhAB;
float dienTich=(1/2)*(dcA * canhBC);
printf("Dien tich cua tam giac ABC la: %f\n",dienTich);
}

You might also like