C Program to Find Area of a Right Angled Triangle

This C program shows how you can to Find Area of a Right Angled Triangle.

Problem statement

Write a C Program to Find Area of a Right Angled Triangle.

C Program to Find Area of a Right Angled Triangle

#include <stdio.h>

int main() {
    float base, height, area;

    // Introduction
    printf("Program to calculate the area of a right-angled triangle.\n");

    // Problem statement
    printf("Enter the base and height of the triangle:\n");

    // User input
    printf("Base: ");
    scanf("%f", &base);

    printf("Height: ");
    scanf("%f", &height);

    // Calculate area
    area = 0.5 * base * height;

    // Output the result
    printf("The area of the right-angled triangle is: %f\n", area);

    return 0;
}

How it works

  1. The program starts by declaring the necessary variables: base, height, and area as floating-point numbers.
  2. The introductory message is displayed using the printf function.
  3. The problem statement asks the user to enter the base and height of the right-angled triangle.
  4. The program prompts the user for input using printf and reads the values of base and height using the scanf function.
  5. The area is calculated using the formula: area = 0.5 * base * height.
  6. The result is printed using the printf function.
  7. Finally, the program ends and returns 0 to indicate successful execution.

Input / output

C Program to Find Area of a Right Angled Triangle

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

This C program calculates the volume and surface area of a sphere using its radius. A sphere is a three-dimensional...
This C program converts a Roman numeral to a decimal number. Roman numerals are a system of numerical notation used...
This C program calculates the value of sin(x) using the Taylor series expansion. The Taylor series expansion is a mathematical...