C Program to find circumference, diameter and area of a circle

Category: C ProgramTags: cprogram function

C Program to find the circumference, diameter and area of a circle

C Program to find the circumference, diameter and area of a circle using function

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

// function declaration
float getDiameter(float);
float getCircumference(float);
float getArea(float);

void main()
{
    float radius;
    float diameter, area, circumference;

    printf("Enter radius of circle: ");
    scanf("%f", &radius);

    diameter = getDiameter(radius);
    circumference = getCircumference(radius);
    area = getArea(radius);

    printf("Area of diameter: %0.4f\n", diameter);
    printf("Area of circumference: %0.4f\n", circumference);
    printf("Area of circle: %0.4f", area);
}

float getDiameter(float radius)
{
    return 2 * radius;
}

float getCircumference(float radius)
{
    return 2 * M_PI * radius;
}

float getArea(float radius)
{
    return M_PI * (radius * radius);
}

Output

Output

Enter radius of circle: 1
Area of diameter: 2.0000
Area of circumference: 6.2832
Area of circle: 3.1416