C ++中n行的最大交点

在本教程中,我们将讨论一个程序以查找n条线的最大交点

为此,我们将提供许多直线。我们的任务是找到给定线数满足的最大交点数。

示例

#include <bits/stdc++.h>
using namespace std;
#define ll long int
//finding maximum intersection points
ll countMaxIntersect(ll n) {
   return (n) * (n - 1) / 2;
}
int main() {
   ll n = 8;
   cout << countMaxIntersect(n) << endl;
   return 0;
}

输出结果

28