forked from vikhyatsingh123/Naruto-Shippuden
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcount.py
41 lines (37 loc) · 1.09 KB
/
count.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// C++ code to count the number of possible triangles using
// brute force approach
#include <bits/stdc++.h>
using namespace std;
// Function to count all possible triangles with arr[]
// elements
int findNumberOfTriangles(int arr[], int n)
{
// Count of triangles
int count = 0;
// The three loops select three different values from
// array
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
// The innermost loop checks for the triangle
// property
for (int k = j + 1; k < n; k++)
// Sum of two sides is greater than the
// third
if (arr[i] + arr[j] > arr[k]
&& arr[i] + arr[k] > arr[j]
&& arr[k] + arr[j] > arr[i])
count++;
}
}
return count;
}
// Driver code
int main()
{
int arr[] = { 10, 21, 22, 100, 101, 200, 300 };
int size = sizeof(arr) / sizeof(arr[0]);
// Function call
cout << "Total number of triangles possible is "
<< findNumberOfTriangles(arr, size);
return 0;
}