C Program to Find the Area of a Circle

This C program calculates the area of a circle using its radius.

Problem Statement

  1. The program structure starts with the problem statement, followed by the input and output sections.
  2. The variable declaration, calculation, and formatting of the output remain the same as in the previous program.

C Program to Find the Area of a Circle

#include <stdio.h>

int main() {
    // Intro
    printf("C Program to Calculate the Area of a Circle\n");
    printf("------------------------------------------\n");

    // Problem Statement
    printf("Given the radius of a circle, this program calculates its area.\n");

    // Variables
    float radius, area;
    const float PI = 3.14159;

    // Input
    printf("\nEnter the radius of the circle: ");
    scanf("%f", &radius);

    // Calculation
    area = PI * radius * radius;

    // Output
    printf("\nThe area of the circle with radius %.2f is: %.2f\n", radius, area);

    return 0;
}

How it works

  1. We begin by including the necessary header file, stdio.h, which provides input/output functionality.
  2. Inside the main function, we declare the variables radius and area as floats, and the constant PI with a value of 3.14159.
  3. We display an introductory message and the problem statement using printf.
  4. The user is prompted to enter the radius of the circle using printf.
  5. The value entered by the user is read into the radius variable using scanf.
  6. The area of the circle is calculated using the formula area = PI * radius * radius.
  7. Finally, the calculated area is displayed on the screen using printf

Input / output

C Program to Find the Area of a Circle

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...