C Program to Find the Sides of a Triangle.

In this C programming tutorial, we will learn how to find the Sides of Triangle in  C programming language.

C Program to Find the Sides of a Triangle

#include<stdio.h>
#include<math.h>

float distance(int x1,int x2,int y1,int y2)
{
    float distance;
    distance=sqrt(((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)));
      return distance;
}
int main()
{
    int x1,x2,x3,y1,y2,y3;
    float a1,a2,a3;
    
    printf("Enter the x-coordinate of vertex A\n");
    scanf("%d",&x1);
    printf("Enter the y-coordinate of vertex A\n");
    scanf("%d",&y1);
    printf("Enter the x-coordinate of vertex B\n");
    scanf("%d",&x2);
    printf("Enter the y-coordinate of vertex B\n");
    scanf("%d",&y2);
    printf("Enter the x-coordinate of vertex C\n");
    scanf("%d",&x3);
    printf("Enter the y-coordinate of vertex C\n");
    scanf("%d",&y3);
    a1=distance(x1,x2,y1,y2);
    a2=distance(x2,x3,y2,y3);
    a3=distance(x1,x3,y1,y3);
    printf("Length of side AB is %.1f\n",a1);
    printf("Length of side BC is %.1f\n",a2);
    printf("Length of side AC is %.1f\n",a3);
    
    return 0;
}

In the above C program, we learned how to find the Sides of the Triangle in the C programming language.

1 Comments

Leave a Reply

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

Shopping cart