Write a Program that calculates the area of a circle and accepts radius from the user

By | October 4, 2021

Problem Statement

We need to write a program in C, C++, and Python that accepts the radius of the circle from the user and calculates its area. To Calculate the area of a circle we can use the following formula

area of the circle (A)= πr2

A = area of a circle

π = pi which value is 3.14

r = radius of the circle.

Vamware

C Program that calculates the area of a circle and accepts radius from the user

#include <stdio.h>

int main()
{	
	float A, r;
	
	//input the circle radius
	printf("Enter the radius of the circle in cm: ");
	
	scanf("%f", &r);
	
	//area of the circle 
	A= 3.14*r*r;
	printf("The area of the circle is: %.2f cmsq", A);
	return 0;
}

Output

Enter the radius of the circle in cm: 3
The area of the circle is: 28.26 cmsq

C++ Program that calculates the area of a circle and accepts radius from the user

#include<iostream.h>
#include< conio.h>
#include<math.h>
void main()
{
clrscr();
float A,r;
cout<<"Enter the radius of the circle in cm: ";
cin>>r;
A = 3.14*pow(r,2);
cout<<"The area of the circle is: "<<A <<" cmsq";
getch();
}

Output:

Vamware
Enter the radius of the circle in cm: 3
The area of the circle is: 28.26 cmsq

Python:

r = float(input("Enter the radius of the circle in cm: "))
A = 3.14*(r*r)
print("The area of the circle is:",A,"cmsq")

Output:

Enter the radius of the circle in cm: 3
The area of the circle is: 28.26 cmsq

 

Wrapping Up!

In this programming tutorial, we learned how to implement a Circle Area calculator in C, C++, and Python. The program is very simple and straightforward all it does, ask the radius value from the user and calculate the area of the circle based on the entered radius in cm sq.

People are also reading:

Author: Vinay

I am a Full Stack Developer with a Bachelor's Degree in Computer Science, who also loves to write technical articles that can help fellow developers.

Leave a Reply

Your email address will not be published. Required fields are marked *