Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created May 9, 2026 07:02
Show Gist options
  • Select an option

  • Save thinkphp/d81e232c9b436dca9a71957edd09915b to your computer and use it in GitHub Desktop.

Select an option

Save thinkphp/d81e232c9b436dca9a71957edd09915b to your computer and use it in GitHub Desktop.
Determinare puncte colinearea
//Problema:
//Se citesc de la tastatura coordonatele a 3 puncte diferite in plan. Decideti daca aceste puncte sunt colineare.
//punct1(x,y)
//punct2(x,y)
//punct3(x,y)
// panta dreptei determinate de segmentul P1P2 = panta dreptei terminate de segmentul P2P3,
//panta dreptei P1P2 = y1-y2 / x1-x2
// varianta cu panta
//
// | x1 y1 1 |
// | x2 y2 1 | = 0
// | x3 y3 1 |
//daca determinatul este 0 , atunci inseamna ca cele trei puncte sunt colineare
#include <iostream>
typedef struct {
double x, y;
} TPunct;
int main(int argc, char const *argv[])
{
TPunct P[ 3 ];
int i;
printf("Introduceti coordonatele celor 3 puncte:");
for(int i = 0; i < 3; ++i) {
printf("Punctul %d:\nx = ", i + 1);
scanf("%le", &P[i].x);
printf("y = ");
scanf("%le", &P[i].y);
}
/*
| x
| x
| x
|
-----------------
|
|
|
|
*/
if( P[ 0 ].x == P[ 1 ].x || P[ 1 ].x == P[ 2 ].x) {
if(P[ 0 ].x == P[ 2 ].x) {
printf("Punctele sunt colineare.");
} else {
printf("Punctele nu sunt colineare");
}
////panta dreptei P1P2 = y1-y2 / x1-x2
} else {
if((P[0].y - P[1].y) / (P[0].x - P[1].x) == (P[1].y - P[2].y) / (P[1].x - P[2].x)) {
printf("Punctele sunt colineare!");
} else {
printf("Punctele nu sunt colineare!");
}
}
/*
if((P[0].y - P[1].y) / (P[0].x - P[1].x) == (P[1].y - P[2].y) / (P[1].x - P[2].x)) {
printf("Punctele sunt colineare!");
} else {
printf("Punctele nu sunt colineare!");
}
*/
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment