『壹』 c語言求兩直線的交點
1、首先在打開的C語言軟體中,先用for循環輸入兩個集合放到a、b兩個數組中,如下圖所示。

『貳』 求兩直線交點並將交點排序的C語言源代碼
void  jiaodian(int a,int b)   //這是個功能函數,a和b的值通過形參傳過來
{int i,y,k,A[100];
  k=tana;
 for(y=0;y<=100;y++)
     A[y]=(y-b)/k;  //tana(a=0~09)斜率為正,不用排序
 for(i=0;i<=100;i++)
    printf("%4d",A[i]);
}
 
void main()  //主函數
{int a,b;
{ 
   scanf("%d",a);  //通過鍵盤輸入a
   scanf("%d",b);  //通過鍵盤輸入b ,這樣你的a,b就可以是任意的了。
   jiaodian(a,b); //調用上面的功能函數;
 }
試試吧,建議初學者還是從基礎一些的學起,這道題目涉及了函數和數組,沒學直接上手會比較困難~~加油吧
『叄』 急! 用c++程序求兩條直線的交點
比較粗略的答案
#include   <iostream.h>   
  class  line
  { double a,b,c;
  public:
  line ( double a1, double b1, double c1)
  {a=a1;b=b1;c=c1;}
  friend void setpoint(line &A,line &B);
  };
  void setpoint(line &A,line &B)
  { double x;
  if(A.a/B.a!=A.b/B.b)
  {x=-100;
do
{
if(( (-A.c-A.a*x)/A.b -  (-B.c-B.a*x)/B.b ) < 0.00001)
break;
x=x+0.00001;
  }while(1);
  cout<<x<<" "<<(-A.c-A.a*x)/A.b;}
    else cout<<"error"<<endl;}
  
void main ()
{line A(-2,-1,4),B(1,-10,-3);
setpoint(A,B);
}
『肆』 十條直線相交,交點的個數最多是多少個
十條直線相交,交點的個數最多是C(10,2)=45個。
『伍』 同一平面內的五條直線最多有幾個交點,請畫圖說明
一個平面內五條直線兩兩相交時交點最多,按照排列組合計算交點個數為C(5,2)=10 。用圖表示如下:

該表達式不適用於和任意坐標軸垂直的直線
『陸』 c++直線交點數
假設f(n)是n條直線的最大交點數,那麼n+1條直線就是f(n+1)=f(n)+n,因為第n+1條直線最多 增加n個交點
程序很簡單
#include <iostream>
using namespace std;
long f(long n);
int main(int argc, char* argv[]){
     long n;
    cin >> n;
    cout << f(n) <<endl;
   return 0;
}
long f(long n) {
    if(n>1000||n<2) return -1; //異常處理
    long values[1001];
   values[2] = 1;
   for(long i=3; i< n; i ++) {
        values[i] = values[i-1] +i;
  }
  return values[n];
}
『柒』 c語言如何實現兩直線(一般式)求交點,或者說如何解2*3增廣矩陣
二元一次方程組
a1x+b1y=c1
a2x+b2y=c2
當a1b2<>b1a2時,方程組有唯一的一組解。
若a1b2==b1a2,且c1*b2<>b1*c2或a1*c2<>c1*a2時,方程組無解;
若a1b2==b1a2,且c1*b2==b1*c2且a1*c2==c1*a2時,方程組有無數組解:

#include <stdio.h>
int main()
{ double a1,b1,c1,a2,b2,c2,x,y;
scanf("%lf%lf%lf",&a1,&b1,&c1);
scanf("%lf%lf%lf",&a2,&b2,&c2);
if(a1*b2-b1*a2)
{ printf("方程組有唯一的一組解: ");
printf("x=%f ",(c1*b2-b1*c2)/(a1*b2-b1*a2));
printf("y=%f ",(a1*c2-c1*a2)/(a1*b2-b1*a2));
}
else if((c1*b2-b1*c2)||(a1*c2-c1*a2))
printf("方程組無解 ");
else
printf("方程組有無數組解 ");
return 0;
}
『捌』 求兩條直線的交點!! C++
代碼和注釋給你, 自己整理吧
//.h文件
#ifndef _LINE_H_
#define _LINE_H_
#include <stdio.h>
#include <iostream.h>
class Point
{
public:
 /* 點的坐標 */
 int x1;
 int y1;
public:
 void SetXY(int x, int y);
    void GetXY(int &x, int &y);
 
 /* 2個構造函數 */
 Point();
 Point(int x, int y);
};
class Line : public Point /* line繼承point */
{
public:
 /* 另一個點的坐標 */
 int x2;
 int y2;
public:
 void SetPoint(Point* point1, Point* point2);
 /* 3個構造函數 */
 Line();
 Line(int x1, int y1, int x2, int y2);
 Line(Point* point1, Point* point2);
 /* 是否相交 
 ** 相交返回0, 交點為intersect_point
 ** 不相交返回-1, intersect_point為空
 ** 兩直線相同返回1, intersect_point為空
 */
 int Intersect(Line* another_line, Point* intersect_point);
};
#endif
//.c文件
#include "1.h"
Point::Point()
{
 x1 = 0;
 y1 = 0;
}
Point::Point(int x, int y)
{
 x1 = x;
 y1 = y;
}
void Point::SetXY(int x, int y)
{
 x1 = x;
 y1 = y;
}
void Point::GetXY(int &x, int &y)
{
 x = x1;
 y = y1;
}
Line::Line()
{
 x1 = 0;
 x2 = 0;
 y1 = 0;
 y2 = 0;
}
Line::Line(int x1, int y1, int x2, int y2)
{
 this->x1 = x1;
 this->x2 = x2;
 this->y1 = y1;
 this->y2 = y2;
}
void Line::SetPoint(Point* point1, Point* point2)
{
 x1 = point1->x1;
 y1 = point1->y1;
 x2 = point2->x1;
    y2 = point2->y1;
}
Line::Line(Point* point1, Point* point2)
{
 x1 = point1->x1;
 y1 = point1->y1;
 x2 = point2->x1;
    y2 = point2->y1;
}
int Line::Intersect(Line* another_line, Point* intersect_point)
{
 /* y = ax + b */
 int a_my, b_my;
 b_my = (x1 * y2 - y1 * x2) / (x1 - x2);
 a_my = (y1 - y2) / (x1 - x2);
 /* check if point */
 Point* point = (Point*)another_line;
 if(a_my * point->x1 + b_my == point->y1)
 {
  intersect_point = point;
  return 0;
 }
 int a_other, b_other;
 a_other = (another_line->x1 * another_line->y2 - another_line->y1 * another_line->x2) / (another_line->x1 - another_line->x2);
 b_other = (another_line->y1 - another_line->y2) / (another_line->x1 - another_line->x2);
 if(a_other == a_my)
 {
  if(b_my == b_other)
  {
   intersect_point = NULL;
   return -1; //not intersect
  }
  else
  {
   return 1; //the same
  }
 }
 else
 {
  intersect_point->x1 = ((b_other - b_my) / (a_my - a_other));
  intersect_point->y1 = (a_my * intersect_point->x1 + b_my);
  return 0; //intersect
 }
}
/* test */
int main()
{
 Point point1(0, 1);
 Point point2(1, 2);
 Line line1(0, 1, 1, 2);
 Line line2(&point1, &point1);
 Line po;
 int a = line1.Intersect((Line*)&line2, &po);
 if(a == 0)
 {
  cout<<"yes"<<endl;
  cout<<"x = "<<po.x1<<", y = "<<po.y1<<endl;
 }
 else if(a == -1)
 {
  cout<<"no"<<endl;
 }
 else
 {
  cout<<"same"<<endl;
 }
 return 0;
}
『玖』 C語言編寫函數實現求兩個線段的交點(定義一個函數而不是直接寫求解的程序)
欲求二函數交點,必須有二函數的代數表達式,或者必須有兩條線段的端點坐標,否則,不可能得到線段的交點。
『拾』 用C語言製作一個求兩條線段交點的程序
//先判斷兩條線段是否不平行(最好同時判斷是否有交點並且不平行,因為浮//點運算不精確),然後計算兩條線段的交點。以下是C語言代碼:
#include<stdio.h>
#include<math.h>
#define eps 1e-8
#define zero(x) (((x)>0?(x):-(x))<eps)
struct point{double x,y;};
//計算交叉乘積(P1-P0)x(P2-P0)
double xmult(point p1,point p2,point p0){
 return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
//判點是否在線段上,包括端點
int dot_online_in(point p,point l1,point l2){
	return zero(xmult(p,l1,l2))&&(l1.x-p.x)*(l2.x-p.x)<eps&&(l1.y-p.y)*(l2.y-p.y)<eps;
}
//判兩點在線段同側,點在線段上返回0
int same_side(point p1,point p2,point l1,point l2){
	return xmult(l1,p1,l2)*xmult(l1,p2,l2)>eps;
}
//判兩直線平行
int parallel(point u1,point u2,point v1,point v2){
	return zero((u1.x-u2.x)*(v1.y-v2.y)-(v1.x-v2.x)*(u1.y-u2.y));
}
//判三點共線
int dots_inline(point p1,point p2,point p3){
	return zero(xmult(p1,p2,p3));
}
//判兩線段相交,包括端點和部分重合
int intersect_in(point u1,point u2,point v1,point v2){
	if (!dots_inline(u1,u2,v1)||!dots_inline(u1,u2,v2))
		return !same_side(u1,u2,v1,v2)&&!same_side(v1,v2,u1,u2);
	return dot_online_in(u1,v1,v2)||dot_online_in(u2,v1,v2)||dot_online_in(v1,u1,u2)||dot_online_in(v2,u1,u2);
}
//計算兩線段交點,請判線段是否相交(同時還是要判斷是否平行!)
point intersection(point u1,point u2,point v1,point v2){
	point ret=u1;
	double t=((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))
		/((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x));
	ret.x+=(u2.x-u1.x)*t;
	ret.y+=(u2.y-u1.y)*t;
	return ret;
}
int main(void)
{
	point u1,u2,v1,v2,ans;
	printf("請輸入線段1的兩個端點:\n");
	scanf("%lf%lf%lf%lf",&u1.x,&u1.y,&u2.x,&u2.y);
	printf("請輸入線段2的兩個端點:\n");
	scanf("%lf%lf%lf%lf",&v1.x,&v1.y,&v2.x,&v2.y);
	if (parallel(u1,u2,v1,v2)||!intersect_in(u1,u2,v1,v2)){
		printf("無交點!\n");
	}
	else{
		ans=intersection(u1,u2,v1,v2);
		printf("交點為:(%lf,%lf)",ans.x,ans.y);
	}
	return 0;
}
