Use two loops:
      num_triangles = 0
      for i:1 to (N-1)/2
        for j:i+1 to i+j<N
           num_triangles += N-(i+j)

This gives values in increasing order such that c>b>a (c,b,a being lengths 
of sides of the triangle) and sum of any two sides is greater than the 
third.

Consider : 1,2,3,4,5,6
Possible side combinations are:
1,2,4
1,2,5
1,2,6
1,3,5
1,3,6
1,4,6
2,3,6
 
 
On Wednesday, 13 June 2012 22:18:01 UTC+5:30, payel roy wrote:
>
>
> Let's say there are N sides are given. Length of them are like 
> 1,2,3,4,5,....N. 
>
> How do you determine how many tri-angles can be made out of these N sides? 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/9GCZ36hKRy4J.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to