Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <math.h>
- typedef struct trougao{
- double ax, ay;
- double bx, by;
- double cx, cy;
- } TROUGAO;
- double duzina(double ax, double ay, double bx, double by){
- return sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by));
- }
- double povrsina(TROUGAO t){
- double s;
- double d1,d2,d3;
- d1=duzina(t.ax,t.ay,t.bx, t.by);
- d2=duzina(t.ax,t.ay,t.cx, t.cy);
- d3=duzina(t.cx,t.cy,t.bx, t.by);
- s=(d1+d2+d3)/2;
- return sqrt(s*(s-d1)*(s-d2)*(s-d3));
- }
- int poredi (const void *a, const void *b){
- TROUGAO x=*(TROUGAO*)a;
- TROUGAO y=*(TROUGAO*)b;
- double px,py;
- px=povrsina(x);
- py=povrsina(y);
- if(px>py)
- return -1;
- else if(px<py)
- return 1;
- else
- return 0;
- }
- int main () {
- int n,i;
- FILE *ulaz;
- ulaz= fopen ("trouglovi.txt", "r");
- if(ulaz==NULL){
- printf("Greska.\n");
- exit(EXIT_FAILURE);
- }
- TROUGAO *t;
- fscanf(ulaz,"%d", &n);
- if(n<=0){
- fprintf(stderr, "Greska aha greska.\n");
- exit(EXIT_FAILURE);
- }
- t=malloc(n*sizeof(TROUGAO));
- if(t==NULL){
- printf("Neuspesna alokacija.\n");
- exit(EXIT_FAILURE);
- }
- for(i=0; i<n; i++){
- fscanf(ulaz, "%lf%lf%lf%lf%lf%lf", &t[i].ax, &t[i].ay, &t[i].bx,&t[i].by, &t[i].cx, &t[i].cy);
- }
- qsort(t,n, sizeof(TROUGAO), &poredi);
- for(i=0; i<n ;i++){
- printf("%.2lf %.2lf %.2lf %.2lf %.2lf %.2lf\n\n", t[i].ax, t[i].ay,t[i].bx,t[i].by, t[i].cx, t[i].cy);
- }
- free(t);
- exit(EXIT_SUCCESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement