C Program to Find Area of Triangle Using Heron's Formula हेरॉन के सूत्र की सहायता से त्रिभुज का क्षेत्रफल ज्ञात करने का प्रोग्राम

Heron's formula is used to calculate the area of a triangle when the lengths of its three sides are given.

हेरॉन के सूत्र का प्रयोग तब किया जाता है जब किसी त्रिभुज की तीनों भुजाओं की लंबाई दी गई हो तथा उसके आधार एवं ऊँचाई की जानकारी उपलब्ध न हो।

Heron's Formula हेरॉन का सूत्र

The area of a triangle can be calculated using the following formula:

त्रिभुज का क्षेत्रफल निम्न सूत्र की सहायता से ज्ञात किया जा सकता है:

Area = √[s(s − a)(s − b)(s − c)]

Where:

  • a, b, and c are the lengths of the three sides of the triangle.

  • s is the semi-perimeter of the triangle.

जहाँ:

  • a, b तथा c त्रिभुज की तीनों भुजाओं की लंबाई हैं।

  • s त्रिभुज का अर्धपरिमाप है।

Semi-perimeter:

s = (a + b + c) / 2

C Program

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

int main(void)
{
    float area, a, b, c, s;

    printf("Heron's Formula\n");
    printf("Enter three sides of a triangle:\n");

    scanf("%f %f %f", &a, &b, &c);

    /* Check whether sides can form a triangle */
    if (a <= 0 || b <= 0 || c <= 0 ||
        a + b <= c || a + c <= b || b + c <= a)
    {
        printf("These sides cannot form a triangle.\n");
    }
    else
    {
        s = (a + b + c) / 2;

        area = sqrt(s * (s - a) * (s - b) * (s - c));

        printf("Area of triangle = %f\n", area);
    }

    return 0;
}

Output

Heron's Formula
Enter three sides of a triangle:
3 4 5
Area of triangle = 6.000000

Explanation व्याख्या:

In this program, the user enters the lengths of three sides of a triangle. These values are stored in variables a, b, and c.

इस प्रोग्राम में यूजर त्रिभुज की तीनों भुजाओं की लंबाई इनपुट करता है। इन मानों को a, b तथा c वेरिएबल्स में स्टोर किया जाता है।

The program first checks whether the given sides can form a valid triangle. The sum of any two sides must be greater than the third side.

प्रोग्राम सबसे पहले चेक करता है कि दी गई भुजाएँ एक वैध त्रिभुज बना सकती हैं या नहीं। किसी भी दो भुजाओं का योग तीसरी भुजा से अधिक होना चाहिए।

The semi-perimeter is calculated using the statement:

अर्धपरिमाप की गणना निम्न स्टेटमेंट द्वारा की जाती है:

s = (a + b + c) / 2;

The sqrt() function is used to calculate the square root of the expression in Heron's formula.

हेरॉन के सूत्र में दिए गए एक्सप्रेशन का वर्गमूल ज्ञात करने के लिए sqrt() फंक्शन का प्रयोग किया जाता है।

The calculated area is displayed using the printf() function.

गणना किए गए क्षेत्रफल को printf() फंक्शन की सहायता से स्क्रीन पर प्रदर्शित किया जाता है।

Note: The sqrt() function is declared in the math.h header file. Some C compilers require linking the math library, for example by using -lm with GCC.

Comments

Popular posts from this blog

C Language Topics in Hindi and English

Top High-Paying Tech Skills to Learn in 2025

Complete C Programming Syllabus | Advanced C Roadmap for Students