To enter Base and Height of a Triangle and to calculate it's Area

 Program:


#include<stdio.h>
#include<conio.h>
void main()
{
    float b, h, area;
    clrscr();
    printf("Enter Base of Triangle : ");
    scanf("%f", &b);
    printf("Enter Height of Triangle :");
    scanf("%f", &h);
    area=((float)1/2)*b*h;        /* or area = 0.5*b*h;  */
    printf("Area of Triangle : %.2f square units", area);
    getch();
}

Output:


Enter Base of Triangle : 10
Enter Height of Triangle : 20
Area of Triangle : 100 square units


No comments:

Post a Comment