• Language

    C

  • Description

    Given three points (x1, y1), (x2, y2), and (x3, y3), check if all the three points fall on one straight line.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdio.h>
#include <stdlib.h>

int main (void)
{
    float slope1, slope2, x1, x2, x3;
    float y1, y2, y3;
    printf ("Enter the value of x1: ");
    scanf ("%f", &x1);
    (void) getchar ();
    printf ("Enter the value of x2: ");
    scanf ("%f", &x2);
    (void) getchar ();
    printf ("Enter the value of x3: ");
    scanf ("%f", &x3);
    (void) getchar ();
    printf ("Enter the value of y1: ");
    scanf ("%f", &y1);
    (void) getchar ();
    printf ("Enter the value of y2: ");
    scanf ("%f", &y2);
    (void) getchar ();
    printf ("Enter the value of y3: ");
    scanf ("%f", &y3);
    (void) getchar ();
    slope1=(y1-y2)/(x1-x2);
    slope2=(y2-y3)/(x2-x3);
    if(slope1==slope2&&y1-slope1*x1&&y3-slope2*x3)
        printf ("The three points fall on one straight line.\n");
    else
        printf ("The three points do not fall on one straight line.\n");
    printf ("Value of slope1: %g\n", slope1);
    printf ("Value of slope2: %g\n", slope2);
    putchar ('\n');
    system ("pause");
    return EXIT_SUCCESS;
}