Example:
Input radius: 10
Output diameter: 20 units
Output circumference: 62.83 units
Output area: 314.16 sq. units
Required knowledge
Basic C programming, FunctionBefore moving on to this program also check how to find diameter, circumference and area of a circle without using functions.
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 */
double diameter(double radius);
double circumference(double radius);
double area(double radius);
int main()
{
float radius, dia, circ, ar;
/* Reads radius of the circle from user */
printf("Enter radius of the circle: ");
scanf("%f", &radius);
dia = diameter(radius); //Calls diameter function
circ = circumference(radius); //Calls circumference function
ar = area(radius); //Calls area 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\n", ar);
return 0;
}
/**
* Finds the diameter of a circle whose radius is given
*/
double diameter(double radius)
{
return (2 * radius);
}
/**
* Finds circumference of the circle whose radius is given
*/
double circumference(double radius)
{
return (2 * M_PI * radius); //M_PI = PI = 3.14 ...
}
/**
* Finds area of the circle whose radius is given
*/
double area(double radius)
{
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
Diameter of the circle = 20.00 units
Circumference of the circle = 62.83 units
Area of the circle = 314.16 sq. units
Happy coding ;)
You may also like
- Function programming exercises index.
- C program to find cube of any number using functions.
- C program to find maximum and minimum between two numbers using functions.
- C program to check even or odd using functions.
- C program to check prime, strong, armstrong and perfect numbers using functions.
- C program to find all prime numbers between given interval using functions.
- C program to find all perfect numbers between given interval using functions.
- C program to print all natural numbers from 1 to n using functions.
- C program to find sum of all natural numbers from 1 to n using functions.
- C program to find reverse of any number using recursion.
- C program to check whether a number is palindrome or not using recursion.