Commit 3c0e07ec by trkall

Lisasin parandatud kolmnurga yl(kolmnurgadParandatudversioon.c)

parent 0fd01664
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <math.h>
typedef struct{
double x;
double y;
}Co;
int MAX = 10;
int sisse(Co X[], int);
double pind(Co A[], Co B[], Co C[], int);
int chkFile(FILE *andmed);
void valja(FILE *S, double pindala[]);
int chkTriangle(Co A[], Co B[], Co C[], int);
int main(void)
{
Co A[MAX];
Co B[MAX];
Co C[MAX];
FILE *S;
int i = 0;
double pindala[MAX];
int chk = 0;
chk += sisse(A, 1);
chk += sisse(B, 2);
chk += sisse(C, 3);
if (chk != 0)
{
return 0;
}
for(i=0;i<10;i++)
{
chk = chkTriangle(A,B,C, i);
if(chk == 0)
{
pindala[i] = pind(A, B, C, i);
} else {
pindala[i] = 0;
}
}
valja(S, pindala);
return 0;
}
int chkTriangle(Co A[], Co B[], Co C[], int i)
{
double ab, bc, ac;
ab = sqrt(pow((B[i].x - A[i].x), 2) + pow((B[i].y - A[i].y), 2));
bc = sqrt(pow((C[i].x - B[i].x), 2) + pow((C[i].y - B[i].y), 2));
ac = sqrt(pow((C[i].x - A[i].x), 2) + pow((C[i].y - A[i].y), 2));
if(ab >= bc && ab >= ac)
{
if(ab < bc + ac)
{
return 0;
}
} else if (bc >= ab && bc >= ac)
{
if(bc < ab + ac)
{
return 0;
}
} else if (ac >= ab && ac >= bc)
{
if(ac < ab + bc)
{
return 0;
}
}
return 1;
}
int sisse(Co X[MAX], int param)
{
FILE *andmed;
int chk = 0;
int i = 0;
if (param == 1)
{
andmed = fopen("aAndmed.txt", "r");
chk += chkFile(andmed);
} else if (param == 2)
{
andmed = fopen("bAndmed.txt", "r");
chk += chkFile(andmed);
} else
{
andmed = fopen("cAndmed.txt", "r");
chk += chkFile(andmed);
}
if (chk == 0)
{
printf("A File is missing!");
return 1;
}
while(i<MAX)
{
fscanf(andmed, "%lf %lf", &X[i].x, &X[i].y);
i++;
}
fclose(andmed);
return 0;
}
double pind(Co A[], Co B[], Co C[], int i)
{
double S;
S = abs((A[i].x * (B[i].y - C[i].y) + B[i].x * (C[i].y - A[i].y) +
C[i].x * (A[i].y - B[i].y)) / 2);
return S;
}
int chkFile(FILE *andmed)
{
if(andmed == NULL)
{
return 0;
}
return 1;
}
void valja(FILE *S, double pindala[])
{
int i;
S = fopen("pindalad.txt", "w");
for(i=0;i<MAX;i++)
{
fprintf(S, "%0.2lf\n", pindala[i]);
}
fclose(S);
}
144.00
917.00
1460.00
218.00
2192.00
1011.00
1892.00
20.00
98.00
63.00
12.87 14.78
-45.78 48.14
-87.41 28.47
42.41 -9.47
-1.78 -4.78
17.11 -41.72
-88.11 58.41
42.41 9.26
5.88 4.18
-14.21 44.12
42.87 11.38
-65.78 43.13
-17.41 24.97
44.41 -21.47
-41.78 -55.98
17.11 -1.72
-18.11 8.41
43.41 1.26
6.78 2.18
-13.21 42.12
12.14 24.47
78.42 -12.45
11.11 65.26
79.41 -12.47
97.41 12.56
-33.48 41.62
51.94 12.46
35.63 23.12
-96.74 13.64
89.12 -35.78
......@@ -4,14 +4,14 @@
//#include <math.h>
typedef struct{
float x;
float y;
double x;
double y;
}Co;
int MAX = 10;
int sisse(Co X[], int);
float *pind(Co A[], Co B[], Co C[]);
double *pind(Co A[], Co B[], Co C[]);
int chkFile(FILE *andmed);
int main(void)
......@@ -21,8 +21,8 @@ int main(void)
Co C[MAX];
FILE *S;
int i = 0;
float *pindala;
int chk;
double *pindala;
int chk = 0;
chk += sisse(A, 1);
chk += sisse(B, 2);
chk += sisse(C, 3);
......@@ -31,6 +31,10 @@ int main(void)
return 0;
}
pindala = pind(A, B, C);
for(i=0;i!=10;i++)
{
printf("%0.2f\n", *(pindala+i));
}
return 0;
}
......@@ -60,21 +64,21 @@ int sisse(Co X[MAX], int param)
while(i<MAX)
{
fscanf(andmed, "%lf %lf", &X[i].x, &X[i].y);
printf("X:%lf\nY:%lf\n", X[i].x, X[i].y);
i++;
}
fclose(andmed);
return 0;
}
float *pind(Co A[], Co B[], Co C[])
double *pind(Co A[], Co B[], Co C[])
{
int i = 0;
float *S = malloc(1000);
double S[MAX];
for(i=0;i<MAX;i++)
{
*(S+i) = abs((A[i].x * (B[i].y - C[i].y) + B[i].x * (C[i].y - A[i].y) +
S[i] = abs((A[i].x * (B[i].y - C[i].y) + B[i].x * (C[i].y - A[i].y) +
C[i].x * (A[i].y - B[i].y)));
printf("S%d:%0.2lf\n", i+1, S[i]);
}
return S;
......
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
//#include <math.h>
typedef struct{
double x;
double y;
}Co;
int MAX = 10;
int sisse(Co X[], int);
double pind(Co A[], Co B[], Co C[], int);
int chkFile(FILE *andmed);
void valja(FILE *S, double pindala[]);
int main(void)
{
Co A[MAX];
Co B[MAX];
Co C[MAX];
FILE *S;
int i = 0;
double pindala[MAX];
int chk = 0;
chk += sisse(A, 1);
chk += sisse(B, 2);
chk += sisse(C, 3);
if (chk != 0)
{
return 0;
}
for(i=0;i<10;i++)
{
pindala[i] = pind(A, B, C, i);
}
valja(S, pindala);
return 0;
}
int sisse(Co X[MAX], int param)
{
FILE *andmed;
int chk = 0;
int i = 0;
if (param == 1)
{
andmed = fopen("aAndmed.txt", "r");
chk += chkFile(andmed);
} else if (param == 2)
{
andmed = fopen("bAndmed.txt", "r");
chk += chkFile(andmed);
} else
{
andmed = fopen("cAndmed.txt", "r");
chk += chkFile(andmed);
}
if (chk == 0)
{
printf("A File is missing!");
return 1;
}
while(i<MAX)
{
fscanf(andmed, "%lf %lf", &X[i].x, &X[i].y);
i++;
}
fclose(andmed);
return 0;
}
double pind(Co A[], Co B[], Co C[], int i)
{
double S;
S = abs((A[i].x * (B[i].y - C[i].y) + B[i].x * (C[i].y - A[i].y) +
C[i].x * (A[i].y - B[i].y)) / 2);
return S;
}
int chkFile(FILE *andmed)
{
if(andmed == NULL)
{
return 0;
}
return 1;
}
void valja(FILE *S, double pindala[])
{
int i;
S = fopen("pindalad.txt", "w");
for(i=0;i<MAX;i++)
{
fprintf(S, "%0.2lf\n", pindala[i]);
}
fclose(S);
}
288.00
1834.00
2920.00
437.00
4384.00
2023.00
3785.00
40.00
196.00
126.00
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
//#include <math.h>
typedef struct{
char *Ax;
char *Ay;
float Bx;
float By;
float Cx;
float Cy;
}Co;
int MAX = 10;
int main(void)
{
Co *tri;
FILE *A;
FILE *B;
FILE *C;
int i = 0;
A = fopen("aAndmed.txt", "r");
while(i<MAX)
{
fscanf(A, "%s %s", (tri+i)->Ax, (tri+i)->Ay);
printf("X%d:%s\nY%d:%s\n", i, *(tri+i)->Ax, i, *(tri+i)->Ay);
i++;
}
fclose(A);
i=0;
B = fopen("bAndmed.txt", "r");
while(i<MAX)
{
fscanf(B, "%lf%lf", &(tri+i)->Bx, &(tri+i)->By);
i++;
}
fclose(B);
i=0;
C = fopen("cAndmed.txt", "r");
while(i<MAX)
{
fscanf(C, "%lf%lf", &(tri+i)->Cx, &(tri+i)->Cy);
i++;
}
fclose(C);
i=0;
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment