# Functions Exercises

## circumference and area of circle using function

Write a C program to input radius of circle from user and find diameter, circumference and area of the given circle using function. How to find diameter, circumference and area of a circle using function in C programming.

#### Required knowledge

In previous exercise we learned to declare and use program with single user defined function. Here in this program we will define more than one user-defined functions in a single program.

#### Declare functions to find diameter, circumference and area of circle

1. First assign a meaningful name to all the three functions. Say function to calculate diameter, circumference and area are - getDiameter(), getCircumference() and getArea() respectively.
2. All the above three functions uses one input i.e. radius of circle to calculate output. Hence all the three function must accept a parameter of double or int type.
3. Finally, all the three functions returns either double or int as output. Hence, return type of the function must be either double or int.
After considering above points function declaration looks like -

```

```

#### Program to find diameter, circumference and area using functions

```
/**
* C program to find diameter, circumference and area of a circle using functions
*/

#include <stdio.h>
#include <math.h> // Used for constant PI referred as M_PI

/* Function declaration */

int main()
{

/* Input radius of circle from user */

dia  = getDiameter(radius);       // Call getDiameter function
circ = getCircumference(radius);  // Call getCircumference function
area = getArea(radius);           // Call getArea function

printf("Diameter of the circle = %.2f units\n", dia);
printf("Circumference of the circle = %.2f units\n", circ);
printf("Area of the circle = %.2f sq. units", area);

return 0;
}

/**
* Calculate diameter of circle whose radius is given
*/
{
}

/**
* Calculate circumference of circle whose radius is given
*/
{
return (2 * M_PI * radius); // M_PI = PI = 3.14 ...
}

/**
* Find area of circle whose radius is given
*/
{
return (M_PI * radius * radius); // M_PI = PI = 3.14 ...
}

```

#### Output

Enter radius of the circle: 10

Diameter of the circle = 20.00 units

Circumference of the circle = 62.83 units

Area of the circle = 314.16 sq. units