C Program to Find Length and Area of Arc in Circular Sector

C Program to Find Length and Area of Arc in Circular Sector

C Program to Find Length and Area of Arc in Circular Sector

Introduction

A circular sector is a portion of a circle enclosed by two radii and their connecting arc. The arc is an important feature of the sector, and two key properties of it are its length and the area it covers. Calculating these properties is not only mathematically enriching but also useful in various real-world applications, such as engineering and architecture.

In this guide, we will explore how to calculate the length and area of an arc in a circular sector using C programming. We'll walk through the formulas, provide the program code, and explain how the code works in a step-by-step manner.


Formulas

To calculate the length and area of the arc, the following formulas are used:

  • Length of the Arc: The length of an arc can be calculated using the formula: Length = (θ / 360) × 2Ï€r, where θ is the central angle in degrees, and r is the radius of the circle.
  • Area of the Sector: The area of the circular sector is calculated as: Area = (θ / 360) × Ï€r².

These formulas are derived from the proportions of the circle's total circumference and area. By using the angle θ, we determine the fraction of the circle occupied by the arc and the corresponding sector.


Code

The following C program calculates both the length and area of the arc based on user input:

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

#define PI 3.141592653589793

int main() {
    float radius, angle, arcLength, sectorArea;

    // Input radius and angle from the user
    printf("Enter the radius of the circle: ");
    scanf("%f", &radius);
    printf("Enter the central angle of the sector (in degrees): ");
    scanf("%f", &angle);

    // Calculate the arc length
    arcLength = (angle / 360.0) * 2 * PI * radius;

    // Calculate the sector area
    sectorArea = (angle / 360.0) * PI * radius * radius;

    // Display the results
    printf("Length of the arc: %.2f units\n", arcLength);
    printf("Area of the sector: %.2f square units\n", sectorArea);

    return 0;
}
    

Output

When you execute the above program, you will be prompted to input the radius of the circle and the central angle. Here is an example of the program's output:

Enter the radius of the circle: 10
Enter the central angle of the sector (in degrees): 90
Length of the arc: 15.71 units
Area of the sector: 78.54 square units
    

Explanation

Let's break down the program into its key components for better understanding:

  • Input Section: The program begins by asking the user to input two values: the radius of the circle and the angle of the sector. These inputs are stored in the variables radius and angle, respectively.
  • Calculations: Using the provided formulas, the program computes:
    • The arc length using arcLength = (angle / 360.0) * 2 * PI * radius.
    • The sector area using sectorArea = (angle / 360.0) * PI * radius * radius.
    Note that the constant PI is defined as 3.141592653589793 for accuracy.
  • Output Section: The calculated values of the arc length and sector area are displayed to the user using printf.