this is the running code to find no of triangles using brute force technique logic: in a triangle having sides a,b,c; then a+b>c(if c is greatest side) correct me if i am wrong.
#include<iostream> #include<conio.h> using namespace std; int max(int a,int b,int c) { return ((a>b?a:b)>c?(a>b?a:b):c); } int main() { int n,a[120],t,p,q; cin>>t; while(t--) { cin>>n; for(int i=0;i<n;i++) cin>>a[i]; int i,j,no_of_triangles=0,sum=0,largest_edge; for(i=0;i<n-2;i++) { for(j=i+2;j<n;j++) { sum=a[i]+a[i+1]+a[j]; largest_edge=max(a[i],a[i+1],a[j]); if(sum-largest_edge>largest_edge) { no_of_triangles++; cout<<a[i]<<" "<<a[i+1]<<" "<<a[j]<<"\n";} } } cout<<no_of_triangles<<endl; } getch(); return 0; } 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/-/WizMjfsoizsJ. 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.