#include <stdio.h>
#include <math.h>
#include <stdlib.h>
typedef struct
{
double n;
double m;
double o;
double s;
}Triangle;
int array (int n)
{
while(1)
{
printf("Enter array size: \n ");
scanf("%d",&n);
fflush(stdin);
if (n>1 && n<=20)
break;
printf("Error \n");
}
printf("\n");
return n;
}
void entercoord(Triangle *p)
{
printf("Enter first line range: \n");
while (1)
{
fflush(stdin);
if(scanf("%lg", &p->n)==1)
break;
printf("Eror! Enter 'n' again:");
}
printf("Enter second line range: \n");
while (1)
{
fflush(stdin);
if(scanf("%lg", &p->m)==1)
break;
printf("Eror! Enter 'm' again:");
}
printf("Enter third line range: \n");
while (1)
{
fflush(stdin);
if(scanf("%lg", &p->o)==1)
break;
printf("Eror! Enter 'o' again:");
}
}
void enter(Triangle z[],int n)
{
int i;
for(i=0;i<n;i++)
{
printf("Enter lines for triangle [%d]\n",i+1);
entercoord(&z[i]);
}
}
void SumArea(Triangle z[20],int n)
{
int j;
for (j=0;j<n;j++)
{
z[j].s=sqrt (((z[j].n+z[j].m+z[j].o)/2)*(((z[j].n+z[j].m+z[j].o)/2)- z[j].n)*(((z[j].n+z[j].m+z[j].o)/2)-z[j].m)*(((z[j].n+z[j].m+z[j].o)/2)-z[j].o));
}
}
void CompareTriangle( Triangle z[20],int n)
{
int i,j;
for(i = 0 ; i <n ; i++)
{
for(j = 0 ; j <n - i ; j++)
{
if(z[j].s < z[j+1].s)
{
Triangle tmp = z[j];
z[j] = z[j+1];
z[j+1] = tmp;
}
}
}
}
void Output( Triangle z[20],int n)
{
int i;
for (i=0;i<n;i++)
{
printf("Line size of Triangle z[%d] : %lg,%lg,%lg \n",i+1,z[i].n,z[i].m,z[i].o);
printf("Triangle area z[%d]: %lg%\n",i+1,z[i].s);
}
}
int main()
{
int n;
Triangle z[20];
n=array(n);
enter(z,n);
SumArea(z,n);
printf("Before sort:\n");
Output(z,n);
printf("Triangle compare:\n");
CompareTriangle(z,n);
printf("Sortirovka po ploshadeam:\n");
Output(z,n);
system("pause");
return (0);
}
z[j].n <= z[j].m <= z[j].o
(z[i].n / z[j].n) = (z[i].m / z[j].m) = (z[i].o / z[j].o)
(z[i].n / z[j].n) = (z[i].m / z[j].m) => ((z[i].n * z[j].m) / (z[i].m * z[j].n)) = 1
(z[i].n / z[j].n) = (z[i].o / z[j].o) => ((z[i].n * z[j].o) / (z[i].o * z[j].n)) = 1
abs(((z[i].n * z[j].m) / (z[i].m * z[j].n)) - 1) < epsilon &&
abs((z[i].n * z[j].o) / (z[i].o * z[j].n)) - 1) < epsilon