Problem 02

author
By Supreme2023-02-14
Problem Statement :
Write a program to find area of triangle (a=h*b*.5) a = area h = height b = base
Code:

#include <stdio.h>

int main()
{

// 2. Write a program to find area of triangle(a=h*b*.5)
// a = area
// h = height
// b = base

float a, h, b;

printf("\tArea Of Triangle ");
printf("\n=====================================");

printf("\n\nEnter The Height : ");
scanf("%f", &h);

printf("\nEnter The Base : ");
scanf("%f", &b);

a = h * b * .5;

printf("\n_____________________________________");
printf("\n\nArea Of Triangle : %.2f Sq. Units", a);
printf("\n\nFormula Used (a=h*b*.5)");
printf("\n_____________________________________\n\n");

return 0;
}

Description :
  • This program calculates the area of a triangle using the formula A = (h * b) / 2, where A is the area, h is the height, and b is the base of the triangle.
  • The program starts by including the standard input-output library "stdio.h" and declaring the main function.
  • Three float variables, a, h, and b, are declared to store the area, height, and base of the triangle, respectively.
  • The program prints the title "Area Of Triangle" and a line of equal signs for decoration.
  • The program prompts the user to enter the height and base of the triangle through standard input using scanf.
  • The program then calculates the area of the triangle using the formula a = h * b * .5.
  • The program prints the result of the area of the triangle using printf.
  • The program ends by returning 0 to indicate that it has executed successfully..
Output Image:
Output-image

© Copyright 2022. All right reserved, GTU Coder.