rendered paste body/* intersectia a n segmente */
#include <stdio.h>
#include <conio.h>
struct segment {
int X1,Y1,X2,Y2;
} S [100];
float a1,a2,b1,b2,c1,c2;
int main(void) {
int n,i,j;
printf("n=");scanf("%d",&n);
for(i=1;i<=n;i++) {
printf("\nSegmentul S%d[X1,Y1][X2,Y2]",i);
printf("\nX1=");scanf("%d",&S[i].X1);
printf("\nY1=");scanf("%d",&S[i].Y1);
printf("\nX2=");scanf("%d",&S[i].X2);
printf("\nY2=");scanf("%d",&S[i].Y2);
}
for(i=1;i<=n;i++) {
for(j=1;j<=n;j++) {
if(i!=j){
a1=(S[i].Y2-S[i].Y1)/(S[i].X2-S[i].X1);
a2=(S[j].Y2-S[j].Y1)/(S[j].X2-S[j].X1);
b1=S[i].Y1-a1*S[i].X1;
b2=S[j].Y1-a2*S[j].X1;
c1= -(b1-b2)/(a1-a2);
c2= b1+a1*c1;
if ( ( (S[i].X1-c1)*(c1-S[i].X2)>=0) && ((S[j].X1-c1)*(c1-S[j].X2)>=0) && ((S[i].Y1-c2)*(c2-S[i].Y2)>=0) && ((S[j].Y1-c2)*(c2-S[j].Y2)>=0) )
printf("\nS%d se intersecteaza cu S%d",i,j);
else printf("\nS%d nu se intersecteaza cu S%d",i,j);
}
}
}
for(i=1;i<=n;i++) {
printf("\nSegmentul S%d[%d,%d][%d,%d]",i,S[i].X1,S[i].Y1,S[i].X2,S[i].Y2);
}
getch();
}