GTU PPS Practical-2
Logic :
Logic of this program is very simple as everyone knows the basic mathematics to find area of triangle.
Let us quickly recall the formula of the area of a triangle.
Area of triangle (A) = [s(s-a)(s-b)(s-c)]^½
You can also check this : find the area of triangle using the formula A = 0.5 * height * base.
In this program, we have to take the length of sides of a triangle from the user then calculate s = (a+b+c)/2 and then we can calculate the area of triangle.
Here, we have to use math.h library to take square root.
Let's look at the algorithm.
Algorithm :
- START
- Input sides a, b, c of triangle.
- Compute s = (a+b+c)/2.
- Compute ar = s*(s-a)*(s-b)*(s-c) .
- Take area = square root of ar .
- print area.
- STOP
Code :
#include <stdio.h> #include <math.h> int main() { float a,b,c,s,area; printf("Enter the length of side a:"); scanf("%f", &a); printf("Enter the length of side b:"); scanf("%f", &b); printf("Enter the length of side c:"); scanf("%f", &c); s = (a+b+c)/2 ; area = s*(s-a)*(s-b)*(s-c) ; printf("The area of given triangle is %.2f", sqrt(area)); return 0; }
Output :
Here you can see output screen of the code.You can get this type of output if you write above code.
Also check
THANK YOU
0 Comments
Donot make a spam in comment box.