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 finds the Greatest Common Divisor (GCD) of two given numbers. Problem Statement Write a C program that...
This C program calculates the roots of a quadratic equation of the form ax^2 + bx + c = 0....
This C program allows you to find the length of a linked list, which is the number of nodes present...