[ create a new paste ] login | about

Link: http://codepad.org/nwxCyrPg    [ raw code | output | fork ]

C, pasted on Jun 20:
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define MAX 100
struct Diem
{
	float x, y;
};
typedef struct Diem DIEM;

struct TamGiac
{
	DIEM a, b, c;
};
typedef struct TamGiac TAMGIAC;

struct ListTamGiac 
{
	int n;
	TAMGIAC DanhSachTamGiac[MAX];
};
typedef struct ListTamGiac LISTTAMGIAC;
void NhapDiem(DIEM &d)
{
	printf("\nNhap vao x: ");
	scanf("%f", &d.x);

	printf("\nNhap vao y: ");
	scanf("%f", &d.y);
}
void XuatDiem(DIEM d)
{
	printf("(%f, %f)",d.x, d.y);
}

float TinhKhoangCach(DIEM d1, DIEM d2)
{
	return sqrt(pow(d1.x - d2.x, 2) + pow(d1.y - d2.y, 2));
}
/*
Kiem tra tam giac co hop le
*/
// Tra ve 1 => Tam giac
// Tra ve 0 => khong phai tam giac
int KiemTraTamGiacHopLe(TAMGIAC tg)
{
	float AB = TinhKhoangCach(tg.a, tg.b);
	float AC = TinhKhoangCach(tg.a, tg.c);
	float BC = TinhKhoangCach(tg.b, tg.c);

	if(AB + AC <= BC || AB + BC <= AC || AC + BC <= AB)
	{
		return 0;
	}
	return 1;
}
void NhapTamGiac(TAMGIAC &tg)
{
	int Check;
	do{
	printf("\nNhap diem A: ");
	NhapDiem(tg.a);

	printf("\nNhap diem B: ");
	NhapDiem(tg.b);

	printf("\nNhap diem C: ");
	NhapDiem(tg.c);

	Check = KiemTraTamGiacHopLe(tg);

	if(Check == 0)
	{
		printf("\n3 diem khong tao thanh tam giac. Xin kiem tra lai !");
	}

	}while(Check == 0);
}

float TinhChuVi(TamGiac tg)
{
	float AB = TinhKhoangCach(tg.a, tg.b);
	float AC = TinhKhoangCach(tg.a, tg.c);
	float BC = TinhKhoangCach(tg.b, tg.c);

	return AB + AC + BC;
}
float TinhDienTich(TAMGIAC tg)
{
	float p = TinhChuVi(tg) / 2;

	float AB = TinhKhoangCach(tg.a, tg.b);
	float AC = TinhKhoangCach(tg.a, tg.c);
	float BC = TinhKhoangCach(tg.b, tg.c);

	return sqrt(p * (p - AB) * (p - AC) * (p - BC));
}
void XuatTamGiac(TAMGIAC tg)
{
	printf("\nA");
	XuatDiem(tg.a);

	printf("\nB");
	XuatDiem(tg.b);

	printf("\nC");
	XuatDiem(tg.c);

	printf("\nChu vi = %f", TinhChuVi(tg));
	printf("\nDien tich = %f", TinhDienTich(tg));
}

void NhapDanhSachTamGiac(TAMGIAC DanhSachTamGiac[], int &n)
{
	do
	{
		printf("\nNhap so luong tam giac: ");
		scanf("%d", &n);

		if(n < 1)
		{
			printf("\nSo luong khong hop le. Xin kiem tra lai !");
		}
	}while(n < 1);

	for(int i = 0; i < n; i++)
	{
		printf("\nNhap Thong Tin Tam Giac Thu %d",i + 1);
		NhapTamGiac(DanhSachTamGiac[i]);
	}
}
void XuatDanhSachTamGiac(TAMGIAC DanhSachTamGiac[], int n)
{
	for(int i = 0; i < n; i++)
	{
		printf("\nXuat Thong Tin Tam Giac Thu %d",i + 1);
		XuatTamGiac(DanhSachTamGiac[i]);
	}
}

int main()
{
	TAMGIAC DanhSachTamGiac[MAX];
	int n;
	NhapDanhSachTamGiac(DanhSachTamGiac,n);
	XuatDanhSachTamGiac(DanhSachTamGiac, n);

	getch();
	return 0;
}


Output:
1
2
3
4
5
6
7
Line 17: error: conio.h: No such file or directory
Line 23: error: expected ';', ',' or ')' before '&' token
Line 57: error: expected ';', ',' or ')' before '&' token
Line 80: error: expected ')' before 'tg'
Line 113: error: expected ';', ',' or ')' before '&' token
In function 'XuatDanhSachTamGiac':
Line 134: error: 'for' loop initial declaration used outside C99 mode


Create a new paste based on this one


Comments: