123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- /*
- * Copyright (C) 2020, 2019, 2018, 2017 Girish M
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- */
- /*-----------------------------------
- Name: Girish M
- Roll number: MTech CS 13
- Date: 20/07/2017
- Program description: Calculate area of triangle using coordinates
- Acknowledgements: Hero's formula
- ------------------------------------*/
- #include <stdio.h>
- #include <math.h>
- float areaTriangle(float []);
- const unsigned length = 6;
- int main(void)
- {
- float cdn[length];
- unsigned i;
- printf("\nEnter 3 coordinates of triangle (x1,y1), (x2,y2) and (x3,y3)\n");
- for(i=0; i<length; i++)
- {
- scanf("%f", &cdn[i]);
- }
- printf("\nThe area of triangle is: %.3f\n", areaTriangle(cdn));
- return 0;
- }
- /*Ar. triangle = 1/2 * (x1(y2-y3)-y1(x2-x3)+(x2*y3-y2*x3))*/
- float areaTriangle(float cdn[])
- {
- return fabs((0.5*(cdn[0]*(cdn[3]-cdn[5])-(cdn[1]*(cdn[2]-cdn[4]))+(cdn[2]*cdn[5]-cdn[3]*cdn[4]))));
- }
|