In this program, we are going to share a C program to find area of a triangle. If you are a beginner and want to start learning the C programming, then keep your close attention in this tutorial as I am going to share a C program to find area of a triangle with the output.
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 | #include <stdio.h> #include <stdlib.h> float findArea(int a, int b, int c) { if (a < 0 || b < 0 || c <0 || (a+b <= c) || a+c <=b || b+c <=a) { printf("Not a valid trianglen"); exit(0); } int s = (a+b+c)/2; return sqrt(s*(s-a)*(s-b)*(s-c)); } int main() { int a = 3; int b = 4; int c = 5; printf("Area is %f", findArea(a, b, c)); return 0; } |
Area is 6.000000
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.