# Why it give incorrect output(hackerrank problem)

/* The problem is Small Triangles, Large Triangles | HackerRank

(Sorting of these triangles(sides) in accending order of its area)

for ip
10
67 67 19
3 57 55
33 33 49
61 58 59
23 43 35
48 42 45
23 12 27
41 34 22
26 49 35
63 46 45

expected op:
3 57 55
23 12 27
41 34 22
23 43 35
26 49 35
33 33 49
67 67 19
48 42 45
63 46 45
61 58 59*/

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

struct triangle
{
int a;
int b;
int c;
};

typedef struct triangle triangle;
void sort_by_area(triangle* tr, int n) {
int *temp;
double p;
int s[100];

for (int i=0; i<n; i++) {
p=(double)(tr[i].a+tr[i].b+tr[i].c)/2;
s[i]=sqrt((double)(p*(p-tr[i].a)(p-tr[i].b)(p-tr[i].c)));
}
for (int i=0; i<n; i++) {
printf(“%d\n”,s[i]);
}

``````for (int i=0; i<n-1; i++) {
for (int j=i+1; j<n; j++){

if (s[j]<s[i])
{
triangle t=tr[i];
tr[i]=tr[j];
tr[j]=t;
}
}
}
``````

}

int main()
{
int n;
scanf(“%d”, &n);
triangle *tr = malloc(n * sizeof(triangle));
for (int i = 0; i < n; i++) {
scanf(“%d%d%d”, &tr[i].a, &tr[i].b, &tr[i].c);
}
sort_by_area(tr, n);
for (int i = 0; i < n; i++) {
printf(“%d %d %d\n”, tr[i].a, tr[i].b, tr[i].c);
}
return 0;
}