Program to Calculate the Area of a Circle in C

Calculating the Area of a Circle

The area of a circle is calculated using the formula:

Area = π × r², where 'r' is the radius of the circle.

We will explore three different methods to calculate the area of a circle in C programming.

Method 1: Using Basic Arithmetic

This method directly computes the area using the formula.

#include <stdio.h>
#define PI 3.14159

int main() {
    float radius, area;
    printf("Enter the radius of the circle: ");
    scanf("%f", &radius);
    area = PI * radius * radius;
    printf("Area of the circle: %.2f\n", area);
    return 0;
}
            
Input: 5.0
Output: Area of the circle: 78.54

Method 2: Using a Function

This method uses a function to calculate and return the area.

#include <stdio.h>

#define PI 3.14159

float calculate_area(float radius) {
    return PI * radius * radius;
}

int main() {
    float radius;
    printf("Enter the radius of the circle: ");
    scanf("%f", &radius);
    printf("Area of the circle: %.2f\n", calculate_area(radius));
    return 0;
}
            
Input: 7.0
Output: Area of the circle: 153.94

Method 3: Using Recursion

This method demonstrates recursion, though recursion is not typically needed for simple mathematical operations.

#include <stdio.h>
#define PI 3.14159

float recursive_area(float radius, int times) {
    if (times == 0) return PI * radius * radius;
    return recursive_area(radius, times - 1);
}

int main() {
    float radius;
    printf("Enter the radius of the circle: ");
    scanf("%f", &radius);
    printf("Area of the circle: %.2f\n", recursive_area(radius, 1));
    return 0;
}
            
Input: 4.0
Output: Area of the circle: 50.27
Numbers

Below You will find some of the most important codes in languages like C, C++, Java, and Python. These codes are of prime importance for college semester exams and online tests.

Getting Started

HCF - Highest Common Factor: C C++ Java Python

LCM - Lowest Common Multiple: C C++ Java Python

GCD - Greatest Common Divisor: C C++ Java Python

Binary to Decimal Conversion: C C++ Java Python

Octal to Decimal Conversion: C C++ Java Python

Hexadecimal to Decimal Conversion: C C++ Java Python

Decimal to Binary Conversion: C C++ Java Python

Decimal to Octal Conversion: C C++ Java Python

Decimal to Hexadecimal Conversion: C C++ Java Python

Binary to Octal Conversion: C C++ Java Python

Quadrants in which a given coordinate lies: C C++ Java Python

Addition of Two Fractions: C C++ Java Python

Calculate the Area of a Circle: C C++ Java Python

Convert Digit/Number to Words: C C++ Java Python

Finding Roots of a Quadratic Equation: C C++ Java Python