C programming
#include <stdio.h>
Try it Yourself ➠
2.
Calculate area of a Triangle in C
13 May
0
Write a program (WAP) in C to read two numbers from keyboard(User Input) and calculate the area of a Triangle.
#include <stdio.h>
int main()
{
float b, h, area;
printf("Enter Base of the triangle (b):\n ");
scanf("%f", &b);
printf("Enter Height of the triangle (h):\n ");
scanf("%f", &h);
area = (b * h) / 2;
printf("Area of the triangle is = %.2f sq. units\n", area);
return 0;
}
Try it Yourself ➠
Note :-
1. You can also write "area=.5*b*h"
2. %.2f
is used to print fractional values only up to 2 decimal places. You can also use %f
to print up to 6.
Must Read :-
Previous article
Next article
Leave Comments
Post a Comment