Skip to content

TypeScript code snippet – How to find the slope of a line with two points in c?

#include<stdio.h>

void main()
{
    float x1, y1, x2, y2;
    printf("Enter the x of point 1 \n",x1);
    scanf("%f",&x1);

    printf("Enter the y of point 1 \n",y1);
    scanf("%f",&y1);

    printf("Enter the x of point 2 \n",x2);
    scanf("%f",&x2);

    printf("Enter the y of point 2 \n",y2);
    scanf("%f",&y2);

    float slope = (y2 - y1) / (x2 - x1);

    if( x1 == x2 )
    {
         printf("the slope is undefined");
    }
    else
    {
         printf("the slope is %f", slope);
    }
}
See also  Python code snippet - How to get the output in rupees in pandas?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.