C প্রোগ্রাম সহ ত্রিভুজের ক্ষেত্রফল নির্ণয়ের এলগরিদম ও ফ্লোচার্ট

Learn how to calculate the area of a triangle in C using base-height and Heron's formula. Includes beginner-friendly examples with source code.

Introduction

Calculating the area of a triangle is one of the most common and useful problems in beginner-level programming. In this tutorial, we will learn two ways to calculate the triangle's area using C language: (1) when base and height are known, and (2) using Heron’s formula when all three sides are given. We’ll also include algorithms and flowcharts to make your understanding crystal clear.

1. Area of Triangle using Base and Height

Algorithm:

  1. Start
  2. Input base
  3. Input height
  4. Apply formula: area = 0.5 × base × height
  5. Display area
  6. Stop

📊 Flowchart Description:

  • Start
  • ⬇ Input base
  • ⬇ Input height
  • ⬇ Calculate: area = 0.5 * base * height
  • ⬇ Output area
  • ⬇ End
Related Posts

#include <stdio.h>

int main() {
    float base, height, area;
    
    printf("Enter the base of the triangle: ");
    scanf("%f", &base);

    printf("Enter the height of the triangle: ");
    scanf("%f", &height);

    area = 0.5 * base * height;
    printf("Area of the triangle = %.2f", area);
    
    return 0;
}

2. Area of Triangle using Heron’s Formula

Algorithm:

  1. Start
  2. Input three sides: a, b, c
  3. Calculate s = (a + b + c) / 2
  4. Apply formula: area = √(s(s - a)(s - b)(s - c))
  5. Display area
  6. Stop

Flowchart Description:

  • Start
  • ⬇ Input sides a, b, c
  • ⬇ Calculate s = (a + b + c) / 2
  • ⬇ Compute area using Heron’s formula
  • ⬇ Output area
  • ⬇ End

#include <stdio.h>
#include <math.h>

int main() {
    float a, b, c, s, area;
    
    printf("Enter three sides of the triangle: ");
    scanf("%f %f %f", &a, &b, &c);
    
    s = (a + b + c) / 2;
    area = sqrt(s * (s - a) * (s - b) * (s - c));

    printf("Area of the triangle = %.2f", area);
    
    return 0;
}

Conclusion

Whether you're calculating the area of a triangle with base and height or using Heron’s formula, mastering these basic C programs is a vital step for every student. These methods improve your mathematical logic and understanding of C syntax. By combining these programs with algorithms and flowcharts, you'll build a solid foundation for more complex problems.

About the author

Daud
Hey! I'm Daud, Currently Working in IT Company BD. I always like to learn something new and teach others.

Post a Comment

To avoid SPAM, all comments will be moderated before being displayed.
Don't share any personal or sensitive information.