Write a function that calculates the diameter, circumference and area of circle.

  • Diameter = 2 * radius
  • Circumference = 2 * \(\pi\) * radius
  • Area = \(\pi\) * radius\(^2\)

Difficulty level
This exercise is mostly suitable for students
#include<stdio.h>
#include<conio.h>
#define PI 3.14159265359

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

double getCircumference(double radius)
{
	return (2 * PI * radius); 
}

double getArea(double radius)
{
	return (PI * radius * radius);  
}

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

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

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

	printf("The diameter of the circle = %.2f units\n", diameter);
	printf("The circumference of the circle = %.2f units\n", circumference);
	printf("The Area of the circle = %.2f sq. units\n", area);
	getch();
}


Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Width of binary trees - recursive version