File tree Expand file tree Collapse file tree 1 file changed +66
-0
lines changed
Geometry 2D/Lines Intersection Expand file tree Collapse file tree 1 file changed +66
-0
lines changed Original file line number Diff line number Diff line change
1
+ // CPP program to count number of straight lines
2
+ // with n total points, out of which m are
3
+ // collinear.
4
+ #include < bits/stdc++.h>
5
+
6
+ using namespace std ;
7
+ int nCk (int n, int k)
8
+ {
9
+
10
+ int C[k+1 ];
11
+ memset (C, 0 , sizeof (C));
12
+
13
+ C[0 ] = 1 ; // nC0 is 1
14
+
15
+ for (int i = 1 ; i <= n; i++)
16
+ {
17
+
18
+ // Compute next row of pascal triangle
19
+ // using the previous row
20
+ for (int j = min (i, k); j > 0 ; j--)
21
+
22
+ C[j] = C[j] + C[j-1 ];
23
+ }
24
+
25
+ return C[k];
26
+ }
27
+
28
+
29
+ int count_Straightlines (int n,int m)
30
+ {
31
+
32
+ return (nCk (n, 2 ) - nCk (m, 2 )+1 );
33
+
34
+ }
35
+
36
+ // Main Function
37
+ int main ()
38
+ {
39
+
40
+ int n,m;
41
+
42
+ while (true )
43
+ {
44
+
45
+ cout<<" Enter total number of points and number of collinear points\n " ;
46
+ cin>>n>>m;
47
+ if (m>n)
48
+ {
49
+ cout<<" Number of collinear points cannot exceed total number of points\n " ;
50
+ continue ;
51
+ }
52
+ else
53
+ {
54
+
55
+ break ;
56
+
57
+ }
58
+ }
59
+
60
+
61
+
62
+ cout<<" Number of straight lines that can be drawn are " ;
63
+ cout << count_Straightlines (n, m);
64
+ return 0 ;
65
+
66
+ }
You can’t perform that action at this time.
0 commit comments