Q:

Write C program to find diameter, circumference and area of circle using function

0

Write C program to find diameter, circumference and area of circle using function

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.

#include <stdio.h>
#include <math.h>
 
//All Function declaration
double getDiameter(double radius);
double getCircumference(double radius);
double getArea(double radius);
 
 
int main()
{
    float radius, diameter, circle, area;
 
    // Inputting radius of circle from user
    printf("Enter radius of circle: ");
    scanf("%f", &radius);
 
    diameter  = getDiameter(radius);       // Calling getDiameter function
    circle = getCircumference(radius);  // Calling getCircumference function
    area = getArea(radius);           // Calling getArea function
 
    printf("Diameter of the circle = %.2f units\n", diameter);
    printf("Circumference of the circle = %.2f units\n", circle);
    printf("Area of the circle = %.2f sq. units", area);
 
    return 0;
}
 
// Calculating diameter of circle whose radius is given
 
double getDiameter(double radius)
{
    return (2 * radius);
}
 
 
//Calculating circumference of circle whose radius is given
 
double getCircumference(double radius)
{
    return (2 * M_PI * radius); // PI = 3.14
}
 
//Finding area of circle whose radius is given
 
double getArea(double radius)
{
    return (M_PI * radius * radius); // PI = 3.14
}

Result:

Enter radius of circle: 5

Diameter of the circle = 10.00 units

Circumference of the circle = 31.42 units

Area of the circle = 78.54 sq. units

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write C program to print perfect numbers between g... >>
<< Write C program to find prime numbers in given ran...