Click here to Skip to main content
15,911,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
how to find all possible sides of a triangle when the area is given
where the area and sides are natural numbers
Posted
Updated 17-Oct-13 6:49am
v2

On the other hand, I would bet on the Heronian Triangle[^].
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 17-Oct-13 14:23pm    
My 5, but this won't answer the question. The brute-force solution is quite obvious though...
—SA
Andreas Gieriet 17-Oct-13 17:36pm    
What is the sentry, i.e. when to stop "searching" for further solutions?
Cheers
Andi
Sergey Alexandrovich Kryukov 17-Oct-13 18:14pm    
:-)
This is not a programming task but rather a geometrical problem.
Knowing that all triangles with a given base side and a given height have the same area, you can chose for a given area an arbitrary base side and have the adjacent point sweep from infinite left to infinite right on a parallel of height distance to the baes line, always maintaining the same area (two times the area = base length times hight). This gives infinte number of sides for each arbitrarily chosen base line.

So, the question is, if there are further constraints. If not, you have infinite number of sides and even worse, some two sides may become infinite, even for a finite area.

Cheers
Andi

PS: There may for a given area be no or many solutions for integral numbers.
 
Share this answer
 
v3
My best bet would be Herons Formula[^]
 
Share this answer
 
v2
C#
for (a=1;a<=s;a++{
        for(b=1;b<=s;b++){
            for(c=1;c<=s;c++){
                if((a+b>c)&&(b+c>a)&&(c+a>b)){
               k=(a+b+c)%2;
                if(k==0){
                   p=(a+b+c)/2.0;
                    s1=sqrt(p*(p-a)*(p-b)*(p-c));

if(s==s1)
print
 
Share this answer
 
Comments
Andreas Gieriet 17-Oct-13 17:34pm    
What is s and why do you stop at s? Why not at s2 or something else?
Andi

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900