In this post, we have explained a program that calculates the area of a circle and accepts the radius from the user with C+ and Python. So let us get started.
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.
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:
Enter the radius of the circle in cm: 3
The area of the circle is: 28.26 cmsq
Python Program that Calculates the Area of a Circle
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:
- WAP to print the truth table for XY+Z
- Python Program to Find ASCII Value of Character
- WAP to find the average of list of numbers entered by the user
- Python Program to Find LCM
- WAP to print the 1 to 10 Multiples of a Number
- Python Program to Make a Simple Calculator
- WAP to calculate the Factorial of an Integer
- Python Program to Find the Sum of Natural Numbers
- WAP to Display Fibonacci Series
- Most Asked Pattern Programs in C
Leave a Comment on this Post