C Program to Find Centroid of a Triangle

This C Program will help you to find the Centroid of a triangle.

The centroid is a point where all the three medians of the triangle intersect. Therefore, the centroid of the triangle can be found by finding the average of the x-coordinate’s value and the average of the y-coordinate’s value of all the vertices of the triangle.
Centroid of points, A, B and C is (x1+x2+x3)/3, (y1+y2+y3)/3.

C Program to Find Centroid of a Triangle

#include < stdio.h >
  int main() {
    int x1, x2, x3, y1, y2, y3;
    float x, y;
    printf("Enter x1\n");
    scanf("%d", & x1);
    printf("Enter y1\n");
    scanf("%d", & y1);
    printf("Enter x2\n");
    scanf("%d", & x2);
    printf("Enter y2\n");
    scanf("%d", & y2);
    printf("Enter x3\n");
    scanf("%d", & x3);
    printf("Enter y3\n");
    scanf("%d", & y3);
    x = x1 + x2 + x3;
    x = x / 3;
    y = y1 + y2 + y3;
    y = y / 3;
    printf("Centroid is (%.1f , %.1f)", x, y);
    return 0;


Enter x1                                                                                                                        
Enter y1                                                                                                                        
Enter x2                                                                                                                        
Enter y2                                                                                                                        
Enter x3                                                                                                                        
Enter y3                                                                                                                        
Centroid is (56.7 , 63.3)