Dr. A.P.J. Abdul Kalam Technical University, Lucknow
KCS151 / KCS251 Programming for Problem Solving - Using C Language
Lab Exercises
1. Write a program to calculate the area of a triangle using the formula at = √s(s-a)(s-b)(s-c).
/*
File: Prgrm01.c
Author: Aditya Saini
Date: Jan 15, 2021
Description: Program to calculate the area of a triangle using formula at = √s(s-a)(s-b)(s-c).
*/
#include <stdio.h>
#include <math.h>
int main (void)
{
float A, B, C;
float S;
float AT;
//Input length of Sides.
printf ("Input Side A: ");
scanf ("%f", &A);
printf ("Input Side B: ");
scanf ("%f", &B);
printf ("Input Side C: ");
scanf ("%f", &C);
//Calculate Semi-Perimeter of triangle (S) = (A+B+C)/2
S = (A + B + C) / 2;
//Calculate Area of triangle (AT) = √s(s-a)(s-b)(s-c)
AT = sqrt (S * (S - A) * (S - B) * (S - C));
//Print result
printf ("Area of triangle: %.2f", AT);
};
Output
Input Side A: 20
Input Side B: 30
Input Side C: 45
Area of triangle: 239.06
No comments:
Post a Comment
Please do not post spam links.